Reverse Animator Animation [SOLVED]

I have a 2D animation handled by the Animator (walking forward) that I want to play in reverse when walking backward.

This should be simple to do but is so far eluding me. I figured out I can flip the Animator.speed value to -1 to play it in reverse but this causes a glitch where the animation plays in reverse for a while but then gets stuck on the first frame and there is no clear reason why this is happening. I checked my code and it has nothing to do with an error in the code itself.

Searching around I found a few ‘solutions’ that involve duplicating the ordinary forward STATE and setting its Speed to -1 but the solution is very inelegant for a bunch of reasons. Also, being able to simply reverse the forward animation allows me to start going backwards from whatever frame is currently active, yielding a much nicer looking result. Any help is appreciated!

In 5.1.1 you can now change state speed at runtime.

1 Like

Perfect timing for this update. Worked a charm!

Here’s how I made it work:

void Update()
{
  float strafeDirection = 1;

  if (Strafing)
  {
       if ((moveX < 0 && FacingRight) || (moveX > 0 && !FacingRight))
       {
            strafeDirection = -1;
       }
  }
  anim.SetFloat("StrafeDirection", strafeDirection);
}

And in the animator I just added StrafeDirection as a parameter, and in the particular state that handles the animation I set the Speed multiplier to the StrafeDirection parameter. Easy! Wonder why it took so long to add this…

I can’t use -1
I get this warning on console ! using Unity 5.3
Animator.speed can only be negative when Animator recorder is enabled. Animator.recorderMode != AnimatorRecorderMode.Offline
Also see this :frowning:

In Unity 5.3.1p1, if I set the speed of an AnimationState in the MecAnim Inspector to -1, my animation isn’t starting at the very end of the animation (it’s 1 second, 20 frames long). I added AnimationEvents and I only see the ones fired at 1 second (1:00) and then backwards to the start of the animation (0:00). The animation frames past 1:00 never play and any corresponding AnimationEvents set past 1:00 never fire.

Does not work in 5.3.2f1 Plays until frame 0 then gets stuck

1 Like

I was able to get it to work by making sure the Apply Root Motion checkbox was off. This is a change from Unity 4!