- Home /
Question by
networkZombie · Feb 28, 2011 at 01:34 AM ·
aienemyfollow
Need help with enemy AI
K so I have a sphere which is the enemy and want it to look at and follow my first person controller. I got it to look at the target but i have no idea how i make it move. i want it to be like the monster in this video - http://www.youtube.com/watch?v=gWggVbFl2QI . I have this so far -
var target : Transform;
function Update() {
transform.LookAt(target);
}
I tried the smoothFollow script but the sphere always stays behind the player
Comment
Best Answer
Answer by AngryOldMan · Feb 28, 2011 at 02:13 AM
perhaps something like this is what you are looking for
var rotate = Quaternion.LookRotation(LookAtTarget.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, damp);
transform.Translate (0,0,speed*Time.deltaTime);
Thanks that worked although i changed it a bit -
while( attackRange < Vector3.Distance(target.position, transform.position)) { transform.LookAt(target); transform.Translate (0,0,speed*Time.deltaTime); }