So I’m trying to get the enemy object to chase an object called and tagged player. This is my enemy script. Lose condition works fine. The problem I’m having is the enemy chases the player extremely slowly and seems to chase the player no matter how far away they are. I only want it to chase within the chaseDistance variable. I know 150 seems large I have a big scene though. Any help/education would be greatly appreciated!
var player : Transform;
var speed : float = 10;
var chaseDistance = 150;
function Update()
{
/****************************** Enemy Movement AI **************************/
if(Vector3.Distance(transform.position,player.position) <= chaseDistance)
{
transform.LookAt(player);
transform.position += transform.forward*speed*Time.deltaTime;
}
/**************************************************************************/
/****************************** Lose Conditions ***************************/
var distToPlayer = (transform.position - player.position).sqrMagnitude;
if( distToPlayer < 5.0 ) {
print ("You lost");
}
/**************************************************************************/
}