- Home /
Stopping one animation and starting another.
Alright, I'm new to Unity, but have a little experience(Not much) with Java Script.
I am trying to make FPS character animations
This is what I have.
function Start ()
{
animation.wrapMode = WrapMode.Loop;
animation["Walk"].layer = 1;
animation.Stop();
}
function Update ()
{
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("Walk");
else
animation.Stop("Walk");
animation.CrossFade("Idle");
}
Everything works fine, except for some rare occasions when the hand stops before the animation is over, and his hand is idling in front of his face. I want them to switch to the idle animation all together.
So what I want is the animation to be two separate animations. When I walk I do the walking animation. When I Idle I do the Idle animation. No inbetweens.
Any help would be appreciated.
Answer by MorphVGX · Sep 26, 2011 at 10:04 AM
You need to check if the length of your animation matches the length you need to specify when importing the animation. I suggest you use split animation even if it is one animation, and there you set the number of frames your animation has.
Also, I suggest you use some sort of state machine so your aren't calling CrossFade every frame when your Input condition is true/false.
On the other hand, Crossfade will make you go from one animation to the other, so you don't need to stop the animation or else there will be no animation to blend with. Stop and then play make sense (but the animation change won't be smooth), but stop and cross fade do not make sense. I hope this helps.
Answer by yeoldesnake 1 · Sep 26, 2011 at 09:49 AM
You do not need an animation.Stop() when using animation.Crossfade().
This is because CrossFade fades one animation into the other, so i am guessing removing that line could potentially solve your problem.
Your answer
Follow this Question
Related Questions
character animation 0 Answers
FPSInputController and Character Animation 1 Answer
Trouble with Load Level 2 Answers
Expecting EOF found else?? 1 Answer
Character animation problem 1 Answer