Reputation: 6447
I'm animating Mario in order to learn Unity. I've gotten a state machine running that allows Mario to run left and right (and idle). What I am concerned with is what happens when I tap the arrow key to take just a little step the animation is a little bit longer than the movement on the screen. Mario is walking a little bit in place.
What would the correct approach be to make this look good? My state machine has states where it goes from idle to walk (left/right) and then back. Would a better way be to include a MicroWalkLeft/Right in between the Idle and WalkLeft/WalkRight states or maybe interrupt the animation when the arrow keys are released? I'm using triggers to start/stop the animations and here is the snippet for starting WalkLeft.
animator.ResetTrigger("Idle");
animator.SetTrigger("WalkLeft");
Upvotes: 0
Views: 165
Reputation: 136
From my experience triggers are used for animations that shouldn't be stopped. In other words for one shot animations.
In your case since you want "micro" steps I'd use booleans to set "walk left" or "walk right" to true
or false
. So Idle transitions to WalkRight when "walk right" boolean is true
and goes to Idle when it's false
. Your transitions also need to have no exit time, or there's no way to have "micro" steps, because your animation can be interrupted at any time the user stops pressing the key and the boolean is set to false.
To go even further you can merge the WalkLeft and WalkRight animations into one and use blend trees to set the direction left or right, then you have only one boolean "walk" that enters the animation and a direction vector that controls the left or right animation.
Upvotes: 0