Vector3.movetowards, stopping at a point.

So i’m using vector3.movetowards to animate a bear in my game. Basically to have the bear chase the player once the player has reached a certain point. It works to say the least, but I’m trying to get it to stop once it has gotten within a certain range of the player. I’m not quite sure how to do this though. Any help would be greatly appreciated. Thank you in advance.

Posting your code would have been helpful to provide a focused answer, but here is a general solution (from among several possible solutions). It works by calculating an endPos for the MoveTowards() that is ‘approachDist’ away from the player.

var endPos : Vector3;
var dir = transform.position - player.position;

if (dir.magnitude > approachDist) {
    endPos = player.position + dir.normalized * approachDist;
}
else {
    endPos = transform.position;
}

‘endPos’ would be the Vector3 used for the second parameter in the MoveTowards. ‘approachDist’ is the closest you want to allow the bear to come to the player.

Another solution is to only execute the MoveTowards when the distance is big enough:

  if ((player.position - transform.position).magnitude > approachDist) {
       // Exectue MoveTowards() here.
  }