- Home /
Animation will not Return to Proper State
Hello everybody,
I have an issue that makes no sense to me. I am working on code for an enemy. All of my animations play as they should. However, once the enemy has begun his attack cycle, it will never return back to a non attacking state in its animation. This is especially odd because when I watch the animation cycle in the animator window, it shows that isAttacking is true while he attacks, and isAttacking is false when the player is out of range. But even while I am out of range, and isAttacking shows false, the enemy still stays in his attacking animations from that point forward.
I am wondering why the system knows that the enemy is not attacking (`isAttacking = false`) but the animation continues. I'm just unsure of where the problem is. The code is simple, thus it should be right. I set the boolean so that the animator transitions correctly into fighting and shows the checkbox as true
once that state has been reached, but when I move beyond the appropriate attackDistance
the enemy is stuck in his animation state, and does not return to walking or running or whatever I might want it to be.
Thanks for your assistance. I am hoping for possible brainstorming on this issue. I would provide code, but the relevant pieces are so simple that I don't think it is relevant. I was going to provide pictures, but the file size was too large. I'm more curious if this is an issue that people have come across before. And if so, how did they solve it.
No matter how simple the code, it will always help us answer. $$anonymous$$y guess is that once it is set back to false, nothing is telling it to play a different animation. It's hard to say though without seeing any code :p Posting it will help your question be answered faster
When you move out of range and the isAttacking animator parameter becomes false in the Animator window, what state is active in the Animator window? (i.e., what state has the little blue progress bar running in it?) $$anonymous$$aybe your script is setting the parameter correctly but the transition from attack-->idle state isn't triggering.
@ToniLi, it stays on attack
... that is what is so mysterious and confusing. while it says isAttacking
is false
in the animator window, it continues playing the attack animation.
Please provide a code sample, you might have overlooked something that someone else can spot!
Ah, I see, this must be $$anonymous$$ecanim. Unfortunately I don't have any experience with it. I wish I could help though. I voted your question up though so hopefully someone else that knows mecanim will see it.
Answer by TonyLi · Jun 21, 2013 at 02:33 AM
In a transition, all conditions must be true.
The attack-->walk transition never fires because distance is never greater than 0.01. In Update(), just add this line:
myAnimator.SetFloat("distance", distance);
thanks, @TonyLi all I had to do was change the parameter criteria from 0.01 to an appropriate distance that I liked. Thanks again to everybody that offered help and brought me closer to the successful conclusion of this problem.
Answer by Ben-Stoneman · Jun 20, 2013 at 12:49 PM
When the player is out of range of the enemy then nothing stops the animation "attack" from playing.
When the player is out of range of the enemy have it check whether to peruse the player or go idle and start the animation depending on the result.
Your answer
Follow this Question
Related Questions
Combining two animations to be one 0 Answers
Mecanim mysterious curve 2 Answers
Mecanim Root Motion Rotation - 180 degree turn. 2 Answers