Search Unity

Root motion doesn't stick when state repeats

Discussion in 'Animation' started by JoeStrout, Oct 11, 2014.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    This has got to be a newbie question... but I guess my google-fu is not strong today.

    I have a "move forward" animation that, as the name implies, makes the character step forward. My Animator has "Apply Root Motion" checked.

    When I execute the forward animation state just once, and then go back to the idle state, my character scoots forward and stays there. But if the forward animation loops (because I haven't met the exit transition criteria — e.g., I'm holding the "forward" button down), then the character scoots forward, and then resets to her original position, scoots forward again, and this repeats all day long.

    Only when I exit the state and go back to Idle does the new position stick. So if I scoot forward, pause, scoot forward, pause, I can make progress across the screen. Otherwise, I just pop back to the starting point again and again.

    So my question is: WTF?

    Thanks,
    - Joe
     
  2. pipedreama

    pipedreama

    Joined:
    Oct 15, 2014
    Posts:
    3
    I am experiencing the exact same problem, just wondering if you have resolved the issue ? In my case I am following the 'stealth game tutorial' supplied by Unity, but i am using my own assets in place of the tutorials assets. as it stands the player movement script is working .. the animations are running, such as the idle when there is no input and running when a directional key is pressed, the only problem is that the anims are looping but the character is staying in the same place !?
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, I haven't figured this one out. I worked around it by changing the state machine so that it can't loop; the forward and back animations exit back to the Idle state, and from there, immediately go back to Forward or Back. This works around the problem... most of the time. Occasionally, while testing, I see my character jump back a step. It appears that sometimes the Forward or Back animation occasionally repeats, despite having way in the state machine to do that as far as I can see.

    In your case, it sounds like the behavior may be more consistent; it could be that the animations simply don't have root motion in them. You can deal with this by "simply" (heh heh) moving the transform when you're in the running state through script. I've had to do that in the past, and it's fiddly but not really all that bad.

    What's really baking my noodle in my case is that it's inconsistent: if I execute (say) the Forward animation just once, and then go to some other state, my character moves forward and stays there. But if I let the Forward animation loop, then at the start of each loop it jumps back to where it was at the beginning of the loop. That makes no sense to me at all.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi joe,

    Can you share your project ? so we can take a look at what is going on. And also which version of Unity are you using?

    Best regards,
     
  5. pipedreama

    pipedreama

    Joined:
    Oct 15, 2014
    Posts:
    3
    cheers for your reply Joe,
    I have animated all the cycles (walk, run, idle and sneak) so that they move for one cycle in the z axis, I'm almost completely sure the 'player movement' script is correct as unity is not finding any errors, also when testing the player moves in the appropriate direction eg. press forwards = player begins to run straight ahead , if up and right are pressed then the player faces 45 degrees between forwards and right and the run animation plays, which is the desired direction.

    i am wondering if its the way i have moved my animation in the z axis ? .. basically i animated the rig via the 'world' control in the z axis and so technically the 'root' has not moved .. I will re-animate the character 'locally' and see if that works so that the root moves off the 'world' control

    cheers again