#Enemy AI Detection
1 messages · Page 1 of 1 (latest)
maybe a
float distance = Vector3.distance(this.transform.position, player.transform.position)
if(distace < radius){
// do something
}
Use spherecast or draw a bunch of raycasts
I think as Papitass said using a spherecast would be the best option
However you could also use a sphere collider that is set to trigger
@halcyon agate We are working on the same thing, this worked for me https://discord.com/channels/243005537342586880/1035518732979666944
public Transform Player;
void update(){
Distance();
}
void Distance()
{
float dist = Vector3.Distance(Player.position, transform.position);
if(dist < 2.5)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
This restarts the game once the Enemy is at 2.5 meters from the player
NOTE: This script is imported into the enemy