#Enemy AI Detection

1 messages · Page 1 of 1 (latest)

halcyon agate
#

how can I make the Enemy AI detect the player within a certain radius, I am using A* Pathfinding for Enemy movement.

vagrant linden
#

maybe a
float distance = Vector3.distance(this.transform.position, player.transform.position)
if(distace < radius){
// do something
}

light light
#

Use spherecast or draw a bunch of raycasts

karmic oracle
#

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

shut beacon
#
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