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");
}
/**************************************************************************/
}
Select the game object this script is attached to and verify the values of the variables in the inspector. Since the variables at the top of the file are public (variables are public by default in Javascript/Unityscript), changes in script values will not change the values used by the program.
– robertbuThe variables in the inspector are the same as in the script. Do you mean I should rename the Speed variable to something like enemySpeed as it may be accessed and changed by another script?
– Zpesh