Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animator doesn't move to next state when speed is negative

Discussion in 'Animation' started by calRoto, Apr 4, 2019.

  1. calRoto

    calRoto

    Joined:
    Feb 19, 2014
    Posts:
    4
    I'm using the Animator for the first time and am trying to create a 2D animation. I hope I'm using the correct terminology to describe what I'm seeing. The sprite is a bird and my animation has three states. The first state is a flying animation, which tends to act as the default animation. When a bool is set to true, the bird should land, and start its landed idle animation. Then, when the bool is set back to false, I want the animator to play the landing animation backwards, then loop the flying animation forwards until the bool is set back to true. My solution for this was to set the speed multiplier (https://docs.unity3d.com/ScriptReference/AnimatorStateInfo-speedMultiplier.html) of the landing animation state to -1 when I want that state to play backwards. This works great, except that it won't ever transition back to the flying animation, even though all of the transition's conditions are true. Instead, it simply loops the backwards landing animation forever. If the speed multiplier is never set to -1, the animator behaves exactly the way I want it to. It seems that playing the animation backwards makes it so that the animator never checks the conditions to see if it should move on.

    So my question is, when does the animator check the animation state's conditions to see if it should move to another state? Is this a bug, or am I just misunderstanding how the animator works?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,554
    Try creating separate states for takeoff and landing. Give them both the same animation but give one a negative speed instead of modifying the speed in a script.
     
    calRoto likes this.
  3. calRoto

    calRoto

    Joined:
    Feb 19, 2014
    Posts:
    4
    I thought of that and tried it earlier, but after your comment I tried again. Good call. Not sure if I changed some other settings, but it works now. Thanks!