AI Patrolling

I have created an enemy to follow the player whenever the player is within range. But after the player went out of range, the enemy does not move back to its own default position for patrolling.

I have 1 questions here,

  1. How to create a patrolling AI?
  2. Can I know how to do set the enemy to go back to its default position for patrolling?


A really easy way to do this is to create a vector 3 position for the enemy on Start()

If the enemy is no longer following the player simply turn them around back to this position. If the enemy is patrolling too far from this position simply turn them around back to this position. That’s probably the simplest way to do this.

So whenever you want them to return to the start point whether it be because the player is out of range or they are too far from the start point or any other variable you want, you can use:


And then have the enemy move in this direction. If you want them to follow specific patrol routes or navigate around walls it will require additional logic.