|
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");
} function Update() { if (!player) return;
} and var minimumRunSpeed = 2.0; function Start () { // Set all animations to loop animation.wrapMode = WrapMode.Loop;
} 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
(comments are locked)
|
|
you can write a much simpler code
i don't understand your question about animations but you can start walk animation when you move with CrossFade method and start idle when you don't move. thanks for the quick reply. iv tried using the code but im getting an error at (4,18). iv got my character tagged as player. : /
Apr 23 '10 at 07:12 PM
KarlH
thank you! iv got it to work now i changed it to var LookAtTarget:Transform; function Update() { transform.LookAt (LookAtTarget); //you look at player with this transform.Translate (0,0,5*Time.deltaTime); //moves with speed in local z and you are looking toward him so you move toward the player //write other codes here }
Apr 23 '10 at 08:02 PM
KarlH
oh yes i takes a transform as an argument.
Apr 24 '10 at 05:33 AM
Ashkan_gc
(comments are locked)
|
