- Home /
Mechanim trigger problem
So I have a really simple state machine. Theres literally an idle and a run. I'm using triggers to change states but I'm getting this problem... So basically lets say you're idling, then you move, I set the Run trigger to true and it triggers the run, then I stop, and it sets the idle to true and plays the idle animation. I'm keeping track of what "animation state" you're in, in my code, that way I can ensure it only calls the trigger once when needed. All of that works fine. But I get this problem where I can make the animation state get stuck in either of the states. I noticed that whatever trigger actually stays true until the transition is finished, this is not me, this is unity. So therefore, if I move, the run trigger gets set to true, then I stop during the transition, then move again quickly, it then gets stuck on the run animation. I know what the problem is, it's unity not setting the trigger to false the next frame which is what the docs say which again, is a load of bollocks. Any help? Need to use triggers btw
Thanks to whoever helps :)
sure thang
void SetAnimation ()
{
if (currentAnimationState != previousAnimationState)
{
switch (currentAnimationState)
{
case AnimationState.idle:
{
animator.SetTrigger ("Idle");
break;
}
case AnimationState.run:
{
animator.SetTrigger ("Run");
break;
}
}
//update the previous animation
previousAnimationState = currentAnimationState;
}
}
You should use boolean ins$$anonymous$$d of the trigger for this kind of setup. Triggers have a weird behaviour that they never get deactivated unless the transition is played . You should use triggers for idle->attack.
Your answer
Follow this Question
Related Questions
Player gets stuck on moving platform 0 Answers
Mechanim state triggers twice 1 Answer
4.5.2 animation BUG: 2D collider colliding with 2d trigger!!! 0 Answers
Can I set Animator State Transition defaults? 3 Answers
physic 2d bug with mass n triggers!? 1 Answer