Course contentsShow
← Unity Game Development
Lesson 376 of 8286. Animation and CinemachineFree lesson

Applying Root Motion for Physical Movement

You will extract motion data from animation clips to drive the character's physical position and rotation through the game world.

In this lesson, you will learn how to shift character movement control from manual scripts to the animation data itself using Root Motion.

What is Root Motion?

In standard character movement, you typically use transform.position += velocity * Time.deltaTime to move a character. However, this often leads to "foot sliding" where the character's feet move at a different speed than the ground plane. Root Motion solves this by extracting the displacement data directly from the animation clip. The "Root" bone—the parent bone of the character’s skeleton—moves in the animation file; Root Motion tells Unity to apply that specific transformation to the actual GameObject in your scene.

Setting Up the Animator

To enable this, you must first ensure your animation clips have "Root Motion" enabled in their Import Settings. Once that is set, look at your Animator component on your character. You will see a checkbox labeled Apply Root Motion.

When this is checked, the animation's movement data overrides manual position updates. If you want to retain some control via code (like modifying the speed), you can leave the box checked but handle the movement logic inside an OnAnimatorMove callback in a script attached to your character:

void OnAnimatorMove() 
{
    // Access the movement data from the Animator
    Vector3 deltaPosition = animator.deltaPosition;
    Quaternion deltaRotation = animator.deltaRotation;

    // Apply the extracted movement to the Rigidbody
    rb.MovePosition(rb.position + deltaPosition);
    rb.MoveRotation(rb.rotation * deltaRotation);
}

Why Use It?

By using OnAnimatorMove, you allow the animation to dictate the "physical" stride length and rotation speed. This ensures that the character's movement speed perfectly matches their stride cycle, providing high-fidelity, realistic motion. It is particularly effective for melee combat animations or precise character movement where foot placement accuracy is vital for immersion.

Key Takeaway: Root Motion delegates spatial displacement to your animation clips, ensuring that your character's physical movement in the game world is perfectly synchronized with their visual animation cycles.