Search Unity

Rotate object with root motion

Discussion in 'Scripting' started by Giustitia, Sep 12, 2018.

  1. Giustitia

    Giustitia

    Joined:
    Oct 26, 2015
    Posts:
    113
    Hi everyone.

    I'm trying to rotate an object with an animator component which has root motion enabled during animation. The animation just moves the root along z axis but it doesn't change rotation at all. Via code, I'm trying to set transform.rotation = Quaternion.LookForward(myDirection); but nothing happens.

    By other side, I noticed that the built-in CharacterController is able to move an object even if has applyRootMotion, so I guess there is a way to get what i'm trying to.

    Thanks for any response :)

    Edit: Bake Into Pose is checked for both Root Transform Rotation and Root Transform Position (Y) on my animation.
     
  2. Giustitia

    Giustitia

    Joined:
    Oct 26, 2015
    Posts:
    113
    So, finally I got answered by myself.

    To solve that, just set the rotation or the position of your "root-motioned object" in the LateUpdate method rather than Update. If you are doing that in a coroutine, just apply your rotation after calling yield return new WaitForEndOfFrame();
    And if you are trying to do this in any other function, just start a coroutine from this function to update your transform inside it as said above :)