Search Unity

[Urgent] Animator replay the same animation when root motion applied.

Discussion in 'Animation' started by YoungXi, Jul 14, 2017.

  1. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Hi guys,

    I have an Animator component attached to a gameObject, and with the applyRootMotion checked. And the simple thing I want to do is replay the animation used by that animator from the same starting position.

    Code (CSharp):
    1.         model.transform.ResetTransformLocal();
    2.         model.animator.rootPosition = model.transform.position;
    3.         model.animator.rootRotation = model.transform.rotation;
    4.         model.animator.Play("someAnimation", -1, 0.0f);
    So I reset the gameObject's transform to default, and then apply its world position to the rootPosition of the animator. But strange things happen sometime: the animation is not guaranteed to be played at the same path each time, which means, the model might be going in the wrong direction next time I replay the animation.