- Home /
Enemy animation help?
So far my enemy follows me around and deals damage but Im having problems scripting its animations. My script doesn't seem to be doing anything but basically what I want it to do is play and idle animation until I come close to it and then for it to walk up to me and then attack me, can anyone help me out?
animation.wrapMode = WrapMode.Loop;
animation["idle"].speed = 0.5;
animation["run"].speed = 2;
animation["attack1"].speed = 1;
var target : Transform;
var dist = 15;
function Awake () {
myTransform = transform;
}
function Start () {
target = GameObject.FindWithTag("Player").transform;
}
function Update () {
if(dist < 2){
animation.CrossFade("attack1");
}
if(dist > 2){
animation.CrossFade("run");
}
if(dist > 15){
animation.CrossFade("idle");
}
}
you dont seem to be setting the distance anywhere...its always at 15 at the moment.
Answer by Montraydavis · Oct 30, 2012 at 04:26 PM
You need to set the distance !
function Update ( )
{
dist = (transform.position - target.transform.position).sqrMagnitude ;
dist *= dist ;
}
This sort of works but my animations don't play how I would like them to. Is there a better way to script what I'm trying to achieve?
Well, according the code you posted, I can't really see anything that would cause your animations to play. . . . Are you sure you are applying your animations to the correct Target, and that they are apart of the models bone structure . . .
I doubt this will change anything, but, try this for each of your animations that need to be looped . . .
animation["animation names"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop ;
Please mark this as answered if this works for you. Thanks!
Nope this doesn't change anything, is there not a better way of coding the animations to play at certain distances?
I am not really sure why this isn't working for you . . . I bet it has something to do with the animations. Try to preview the animations, and tell me if your model animates.
The animations all work fine, Im guessing it must be the script.
Your answer
Follow this Question
Related Questions
I can't script enemy animation 0 Answers
Adding a counter? 1 Answer
Enemy attack/follow Player script? 4 Answers
Enemy Ragdoll help 1 Answer
Enemy Health Problem 2 Answers