- Home /
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 :)
-Clopay
Update - editing the input axes for 2D has no effect - neither for key/mouse OR joystick input.
Thank you, Santosh!
The suggestion you've got is what I'm currently running with, so I know we're on the right track.
I have narrowed it down to the input axis gravity.
Basically I am using Input.GetAxis("Horizontal") for my left/right movement ins$$anonymous$$d of Input.GetButton("Button"). I'm doing this so that the player is not only movable by left/right, and AWSD keys, but also joystick input if they are using a game controller.
The input gravity I mentioned is a setting found in Edit > Project settings > Input. The input gravity defines how quickly the horizontal value (or any other defined value) resets to zero after pushed. This parameter only takes effect if the input type is a button or a key; however, since $$anonymous$$e is an axis, it has no effect. This is a smart thing to do for Unity, but I am at a loss as I don't know how to overcome this without sacrificing the ability to control my plater with a game controller!
Answer by Santosh Patil · Jan 20, 2014 at 11:08 AM
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
Answer by Mijdax · Mar 12, 2016 at 08:15 PM
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
Your answer
Follow this Question
Related Questions
Animation dont change when it should change 1 Answer
Create animation transitions via script. 0 Answers
Animation with bones, Limb Solver knee is bending in wrong way 1 Answer
Talking animation with phonemes smooth transition 0 Answers
How to make a transition animation, intermediate animation between two main states 0 Answers