1
\$\begingroup\$

As stated in the question I've this problem: I'm using Unity and when playing an animation my character moves from point A to point B without my consent. Here's the code:

public class Walk : MonoBehaviour {

    private Animator humanAnimator;
    private iInputProvider input;

    private void Start()
    {
        input = new KeyBoardInput();
        humanAnimator = GetComponent<Animator>();
        walkMe = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        walk();
    }

    private void walk()
    {
        InputWrapper inputWrp = input.GetInputValues();

        animateWalk(inputWrp.verticalMove);
    }

    private void animateWalk(float verticalMove)
    {
        if (-0.1 <= verticalMove && verticalMove <= 0.1) //stand still
        {
            humanAnimator.SetBool("Walk", false);
            Debug.Log(humanAnimator.GetBool("Walk"));
        }
        else if (verticalMove > 0.1) // animate walk forward if the player is walking forward
        {
            humanAnimator.SetBool("Walk", true);
            Debug.Log(humanAnimator.GetBool("Walk"));
        }
        else if (verticalMove < -0.1)
        {
            // walk backward animation needed
        }

    }
}

Note that nowhere in the code I change the object position, i just start the animation. Here's the result:

https://imgur.com/OMvfmYE

note that it's not the effect of the gif, the character actually resets its position after the animation is terminated. I was expecting the character to "run on the place". Anybody has some idea how can I fix this?

EDIT: if I uncheck the "Apply root motion" check box I've this result: https://imgur.com/4FdeCKH . Maybe it could be useful to know that I can't click on "Generate root motion curve" in my animation inspector because it's all uneditable: https://imgur.com/9q3h1cd

\$\endgroup\$
  • 1
    \$\begingroup\$ Probably animation itself has root positioning keys too, try removing them \$\endgroup\$ – Nick Aug 7 '18 at 17:42
2
\$\begingroup\$

There is an option on the Animator Component called "Apply Root Motion" this basically asks if you want the animation itself to control character motion(true, checked) or handle it yourself (false, unchecked), In your case you likely want it disabled.

for extra information on the Animator Component

If you end up on this question from google and the above doesn't help and you've also got your animations from Mixamo try re-downloading the animation with "In Place" ticked, if not ticked it applies root motion that unity cannot override.

\$\endgroup\$
  • \$\begingroup\$ Hi thanks but I've already tryied, the result is actually worse: imgur.com/4FdeCKH now there's this oscillation ... \$\endgroup\$ – JoulinRouge Aug 7 '18 at 17:37
  • \$\begingroup\$ Ok that's strange, how about on your animation clips themselves, does un-checking the different root motion options there make any difference? \$\endgroup\$ – Pheonix2105 Aug 7 '18 at 17:43
  • 1
    \$\begingroup\$ Also did you happen to get the animations from Mixamo? \$\endgroup\$ – Pheonix2105 Aug 7 '18 at 17:44
  • 1
    \$\begingroup\$ If I remember correctly there is an option within Mixamo itself to apply root motion to the models which unity cant override, if you uncheck this and re-download/import the animation that should fix it. \$\endgroup\$ – Pheonix2105 Aug 7 '18 at 17:49
  • 1
    \$\begingroup\$ The option in Mixamo is just called "In Place" \$\endgroup\$ – Pheonix2105 Aug 7 '18 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.