Character Orientation (To Bake, or Not to Bake Into Pose... is that the question?)

This sounds a lot like a very frequently asked question, but I can't seem to wrap my head around it...
I have a series of animation clips in the Animator Controller that play one after another. One of the animations is for the character to turn 180 degrees, next is them standing and looking for a bit, then another turning 180 degrees again. So, she should turn, look, turn again to the original orientation.

Trouble is, when Root Transformation Rotation has Baked Into Pose enabled, after the animation clip is complete - it snaps back to its original orientation. If Baked Into Pose is disabled, the character won't rotate at all.
Oh - and the animator's Apply Root Motion is "Handled by Script".

So... what am I missing? How do I get my character to turn in place and stay facing that direction?

Here's a video that might better explain my issue:
l40k9h

I know this could be easier using Timeline, but it's so buggy I can't be bothered right now.

1 Like

What I ended up doing was writing a behaviour to conduct the rotation, and I turned off the Bake Into Pose under Root Transform Rotation.

using UnityEngine;

public class TransformBehaviour : StateMachineBehaviour
{
    [Tooltip("Time to begin this transform, normalized time")]public float startTransformTime;
    [Tooltip("Time to finish this transform, normalized time")]public float exitTransformTime;
    public Vector3 rotationTransform;
    Quaternion startOrientation;
    Quaternion finalOrientation;

    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        startOrientation = animator.gameObject.transform.rotation;
        finalOrientation = animator.gameObject.transform.rotation * Quaternion.Euler(rotationTransform);
    }

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        float adjustedTime = Mathf.InverseLerp(startTransformTime, exitTransformTime, stateInfo.normalizedTime);
        animator.gameObject.transform.rotation = Quaternion.Lerp(startOrientation, finalOrientation, adjustedTime);
    }
}

If the need comes up, one could add a position transform too.

2 Likes