2D Animation Instant Transition

Hey guys,

I’m having issues with Unity transitioning my 2D sprite animations instantly. This question was already asked here but doesn’t look like it’s getting enough attention.

Goal
I’ve got a 2D sprite animation for a few different states of my character that I’d like to transition between instantly.

Problem my character’s default state is idle. This entire animation is 2 seconds long (2 frames, each playing for 1 second). The walk animation lasts for 2/3 of a second (2 frames, each lasting 1/3 of a second). Once my speed is greater than 0.01, I transition to my walk animation. That happens instantly. Once the speed is below 0.01, it is SUPPOSED to transition back to idling, but it often waits an entire second until the idle animation starts playing (even though the velocity is 0 at this point, so my character is walking in place).

I’ve tried everything I can think of - checking/unchecking the “atomic” option, adjusting the sliders on the transition bar, adding/adjusting an exit time condition, and even scripting the animation completely. I just cannot seem to get this simple thing right. It gets worse when I add in additional states, but I’m just trying to know out the idling - walking - back to idling for now.

Anyone know what’s up? Any input is greatly appreciated :slight_smile:

-Clopay

You can use following code to make instant transition between animation state.

Animator anim;
float runSpeed;//change run speed with your input control
void Start()
{
    anim = GetComponent<Animator>();
}
void Update()
{
   anim.SetFloat("Speed", Mathf.Abs(runSpeed));
}

//-------------------animator settings------------------

make two state as 1> Idle

              2> Walk 

make transition from Idle state to Walk click on transition, see Inspector below conditions select “Speed” tag and set “Greater” and speed value to
0.01. make transition from Walk to Idle Speed->less->0.01

You Probably had the Same Problem as I had. The float which you set (velocity in my case) will slowly decay until its 0 again and while it is not 0 it will keep animating the running state.

What I did: I added variables for MoveDown,Up,Left and Right (Bools) in the animator and in code I checked

IF velocity.x < -0.05f DO MoveLeftInAnimation == true
ELSE MoveLeftInAnimation == false

So as soon as velocity.x drops higher than -0.05 (and lower than 0 of course) it will tell the animator the the character stops walking left