4

So, i am making a little 2D game, and in this game the player can snowboard, so, i made the player animator, and i wanted the player to snowboard doesn't matter the state, so i used the "Any State" state to transition the current animation to the "9_Snowboarding" animation using a bool called "isSnowboarding", and it worked fine.

First Image

The problem began when i wanted the player to jump, i created the jump animation, and i created a bool to make the transition happen called "isJumping", and i set the bool to true by code.

transition settings

Instead of transitioning to the animation and playing it, the animator controller keeps transitioning the "9_Snowboarding" to the "10_SnowboardJumping" multiple times, and i dont know how to solve this.

animation keeps transitioning

Nícolas
  • 406
  • 3
  • 8
  • 24

2 Answers2

8

Alternatively, if you absolutely need a bool there for some reason, you can disable the Option "Can Transition To Self" in the Transition settings of the Any State to your State Die.

AnyState Transition Settings - Can Transition To Self

ForceMagic
  • 6,230
  • 12
  • 66
  • 88
  • If I do that, the animation assigned to the target state no longer loops. Is it mandatory for this flag to be true to have the state animation loop? – Wolfram Aug 04 '20 at 12:59
  • @Wolfram I think so yes, because when it loops it goes back to the same state, which it can't in this case. – ForceMagic Aug 04 '20 at 13:23
5

Particularly in your case you need to use a "trigger" instead of a "bool" parameter.

The problem with bool is that isJumping is always set to true so your condition keeps on matching and you keep on transitioning to the same animation.

"Triggers" on the other hand will disable once used. So try adding something like Jump trigger and set that in your code

Kashif Siddiqui
  • 1,476
  • 14
  • 26
  • Oh wow, actually was my problem too! Unity does not animate the transitioning loop as they usually do when you switch state, might be a particularity of Any State I guess. – ForceMagic Apr 09 '20 at 18:00