Enemy AI Detect And Follow (Need Help)

Hey guys, I’m currently building a horror game on my laptop. But I am having serious trouble with AI Detect and Follow. I want the enemy AI to walk around randomly, but when he detects me from a distance, he follows me! Could someone please help me!

I would have 2 different behaviors :

  • random walking (you should take a look at A* ai)
  • a “follow” : just a circle collider that triggers when player enters.
    just check for player transform.position on a fixed time (build a simple timer to refresh the position you’re targeting) and move forward this position !

Every code here is pretty basic, hope this will help :slight_smile:

You could have the Enemy check the distance of the player- and if it is past a certain limit there is no detection- you could also also fire a ray to the player with a ray/sphere cast of a certain length so if it returns false there is no detection-

First step, is to follow a lot of Unity’s lessons and tutorials, and learn basic coding. the answers here will make more sense to you with a basic understanding of C# code.