- Home /
Enemy to follow the Player
How to make an object to follow the player when the object comes in range with the player. I tried using smooth follow but it didn't work.
Felipe
Comment
Best Answer
Answer by TripodGRANNE · Feb 01, 2012 at 12:56 AM
I dont know what your code looks like but to do this you would have to calculate the distance from the player to the enemy.
Calculating the difference in an if statement and checking to see if it is close enough should work:
Variables i used in this example:
var enemy : Transform;
var startFollow = 5;
if(Vector3.Distance(enemy.position, transform.position) <= startFollow) {
// Your Code Here
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613063614im_/https://answers.unity.com/themes/thub/images/avi.jpg)