- Home /
Animation stoping!!
Hi, This has been bugging me for a long time maybe you can help :) Okay so i have 3 animations (Idle,(ShootandReload << its all one animation because its a bolt action rifle),and walk,,, This is my code
function Update ()
{
if(Input.GetKey("w"))
animation.Play("Walk");
else if(Input.GetKey("mouse 0"))
animation.Play("Shoot");
else
animation.CrossFade("Idle");
}
But when i have the Idle piece of code in there it goes messed up because the shoot/Reload doesn't run through the hole animation if you need more infomation check out this link to see what i meen :)
( http://www.youtube.com/watch?v=q2t32pMhHNQ )
Watch this video to see more :)
Answer by dannyskim · Nov 07, 2011 at 07:05 PM
You may want to rethink your logic. GetKey Returns true while the user holds down the key identified by name. So that means, if you fire, you typically will quickly press the "mouse 0" down and then let it up. When running through the update loop after you shoot, that means your else if statement is then false in the next update cycle, and it will go through the else statement where your idle animation is even though you want your shoot animation to finish.
By definition, CrossFade will IMMEDIATELY crossfade the current playing animation ( shoot ) and fade in the new animation ( idle ), at the default speed since you have not passed in a time value in the animation.CrossFade() arguments. So either you can try using PlayQueued, CrossFadeQueued, or lay out your logic differently to compensate for this change in animation states.
There are several other options that you can go with in animations, it's really an art in-and-of itself. There's blend weights, animation layers, checking if animation.IsPlaying(), and a slew of other things to get to your end point.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Where is the problem? 0 Answers
how do i use two animations on the same object?? 1 Answer
Animation Help!!!!! 1 Answer
Activating Audio When Hitting a collider 2 Answers