right iv got my enemy following my characters when he comes into range. im using two scripts:
var player : GameObject; var speed : float = 1;
function Start () { player = GameObject.FindGameObjectWithTag("Player");
if (!player)
Debug.Log ("ERROR could not find Player!");
}
function Update() { if (!player) return;
var distance = Vector3.Distance( player.transform.position, transform.position);
if ( distance < 20 )
{
Debug.Log ("player is close");
var delta = player.transform.position - transform.position;
delta.Normalize();
var moveSpeed = speed * Time.deltaTime;
transform.position = transform.position + (delta * moveSpeed);
}
else
{
Debug.Log("not close yet " + distance);
}
}
and
var minimumRunSpeed = 2.0;
function Start () { // Set all animations to loop animation.wrapMode = WrapMode.Loop;
animation["idle"].layer = -1;
animation["walk"].layer = -1;
animation.Stop();
}
function SetSpeed (speed : float) { if (speed > minimumRunSpeed) animation.CrossFade("walk"); else animation.CrossFade("idle"); }
my enemy follows me but im stuck with a few things, hoping someone can help me out. first of all the enemy doesn't face me, secondly i dont know how to get his animations playing (i have 2 animations idle, and walk) and he walks through objects too. all help appreciated