I have a enemy ai script he is sup oust to follow you, but instead he just turns and follows you, He dose not walk towards you just follows your movement. I want him to chase you but idk what is wrong and also. the min distance works wrong if i set it to 1 it disappears before it gets to me and if i set it higher it disappears when i walk away. I hope you understand what i mean. Heres the code
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
function Start ()
{
}
function Update ()
{
//Moves towrd player
transform.LookAt (Player);
if(Vector3.Distance(transform.position,Player.position ) >= MinDist) {
transform.position += transform.forward * MoveSpeed*Time.deltaTime;
if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
{
Destroy(this.gameObject);
}
}
}
and also i dont understand how to activate it by a trigger, like he stares at a wall then when i walk into the room he turn around not just dose it when i spawn thanks for any help!