Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Root motion animated character with manual Y rotation of character.

Discussion in 'Animation' started by mariusgeorge, Nov 8, 2018.

  1. mariusgeorge


    Jan 29, 2016
    Well... I have spent hours breaking my head against this.

    I have an animation controller with a bunch of root motion animation states set up.

    I have a third person orbital camera that looks at the character.

    At the start, the character is in a crouched position. When rotating the camera around the character, some root motion crouch rotations will kick in to turn the character where the camera is facing. Works perfectly.

    When W is pressed, the character goes into a walk animation. Also root motion, also works as expected.

    However, I want to turn the character based on the direction the camera is facing.

    This has proved to be impossible or at least difficult enough so that I can't figure it out.

    Setting the character's gameobject rotation manually works - but the root motion gets stuck in the original direction. Setting the character's Animator's "rootRotation" and/or "bodyRotation" quaternions in OnAnimatorIK rotates the character, but the root motion coming from the animation is then stuck on the original plane, and the character just slides in place.

    What's going on here?

    How does one manually rotate a character that is using root motion based animation?

    Extra info:
    - The animator is on the root gameobject.
    - I have played with all the various animation objects for IK, like rotation "based on", position "based on", etc.

    Please help!


    Marius George
  2. PlayingKarrde


    Aug 19, 2013
    Have you tried

    Code (CSharp):
    1. Vector3 targetDir = transform.forward + target.position;
    2. Quaternion rotation = Quaternion.LookRotation(targetDir, Vector3.up);
    3. float RotationYAxis = transform.rotation.eulerAngles.y;
    5. RotationYAxis  = Mathf.LerpAngle(RotationYAxis, rotation.eulerAngles.y, delta * RotateToTargetSpeed);