I have an animation tree that looks something like this:
**
JUMP(If whatAnimation = 3)
^
|
|
ANY STATE --------> Walk(If whatAnimation = 2)
|
|
V
IDLE(If whatAnimation = 1)**
And some code that looks somewhat like this:
if (playerIdle) {animator.SetInteger("whatAnimation", 1);}//Transition to idle animation
if (playerWalking) {animator.SetInteger("whatAnimation", 2);}//Transition to walk animation
if (playerJumping) {animator.SetInteger("whatAnimation", 3);}//Transition to jump animation
However, when I run the code, it keeps playing the first few frames of animation over and over again when it transitions. Why does this happen, and how can I fix it?
EDIT: I actually have about a dozen more animations that are set up in a similar way to this, so that is why I don’t want to individually transition from one animation to another.
Your problem is linking everything to “any state”. “Any state” includes the actual animation.
Here’s a scenario. You are currently idle. But then, you start walking. So…
IDLE -> ANY STATE (walking == true) -> WALK
Now you are walking. But, the walk integer is still true. So…
WALK -> ANY STATE (walking == true) -> WALK
Causing the walk animation to repeat from the start.
As for a solution, the usual way is to link all animation to an “idle” animation, instead of to ANY STATE. I highly recommend doing this.
But it sounds like you might be crazy invested in connecting everything to ANY STATE. This is not impossible, to do this add a “changeAnimation” trigger to all animation conditions, and set this trigger when you want the animation state to change. Something like that might work.