- Home /
Animation state constantly being run, how to work around this?
I'm having an issue with my player controller where I'm constantly triggering an animation state. For example, if I'm holding down W, the up animation state will be triggered but since I'm holding down the button, the state is constantly being run without completing the animation so all I'm seeing is the first frame. I tried to use Has Exit Time which partially fixed it but there is lag between switching animations since the previous animation has to complete before moving to the next state.
In function Update() :
if (Input.GetKey('w'))
{
playerRigidBody.velocity.y = speed;
animator.SetBool("isUp", true);
}
else if (Input.GetKey('s'))
{
playerRigidBody.velocity.y = speed * -1;
animator.SetBool("isDown", true);
}
else{
playerRigidBody.velocity.y = 0;
animator.SetBool("isUp", false);
animator.SetBool("isDown", false);
}
Try use Get$$anonymous$$eyUp ins$$anonymous$$d and so it will only be fired once on key up.
The problem with that is the character will only be moved by a mm since the last else statement is run
I still don't get why it restarts the animation. Probably you do not have the animation set to "Loop" when it should be. Or you have the incorrect return transition set.
I have Loop Time checked off for all the animations. I think the reason the animation restarts is because the trigger variable is always true so the animation state is triggered constantly
It shouldn't constantly be triggered because according to your code you use a Bool and not a trigger. The only reason I can see is if you have "True" set or both "in" and "out" transitions. Or somewhere else in your code it is being reset to false
Answer by Harpnart · Dec 07, 2015 at 08:39 AM
I just realized there is an option called "Can transition to self" ._.