- Home /
Mecanim - How to use "Exit Time" for a state that uses negative speed (anim playing backwards)?
Usually, we can transition from one animation state to the next at the end of the animation using the "Exit Time". But iI have a specific case, that halfway through the animation, I'm changing the speed to negative, so it plays backward, but I would still like to arrive at the next state that would have been called by the "Exit Time". Unfortunately, this doesn't happen since the animation goes back to the start.
Is there a way to achieve this? How?
The only workaround I can think of, would be to track the current animation 'time' for the current state and when it reaches zero, force a transition to a target state.
How about making three clips. Given A is start, B middle and C ending of the actual clip you make the clips AB, BA and BC. And if you reach point B you then decide wether to go on with BC or call the BA animation. So you stay in the normal usage of $$anonymous$$ecanim.
That is way overcomplicated and messy and will not produce the results I'm looking for. I want to play the same animation backwards from whatever position it currently is.
Answer by castor · Oct 17, 2019 at 05:53 PM
After some poking around, I learned the cleanest way to do this is to add a NEW transition for the state that is playing at a negative speed AND set 'Exit Time' to 0.
That way, when the animation reaches 0, it will trigger this new transition to the newly assigned state.
More details here: https://forum.unity.com/threads/stop-animation-half-way-through-and-reverse.487009/
Answer by hexagonius · Oct 17, 2019 at 08:04 AM
As you say it's a specific case and you won't get your result without scripting it. I think your best bet is to perform a manual cross fade. You'd need to check the play time yourself and then do it. Check the Animator API for how to do this:
https://docs.unity3d.com/ScriptReference/Animator.html