0
0
Unityframework~5 mins

Root motion in Unity

Choose your learning style9 modes available
Introduction

Root motion helps your character move naturally by using the animation's own movement instead of coding it manually.

When you want your character's walk or run to match the animation perfectly.
When you want smooth and realistic movement in cutscenes.
When you want to avoid sliding or unnatural movement in animations.
When you want to blend animations and keep consistent character position.
When you want to simplify movement code by letting animations control position.
Syntax
Unity
animator.applyRootMotion = true;
Set applyRootMotion to true on your Animator component to enable root motion.
Root motion uses the movement baked into the animation clip's root bone.
Examples
This enables root motion on the Animator component attached to the GameObject.
Unity
Animator animator = GetComponent<Animator>();
animator.applyRootMotion = true;
Override OnAnimatorMove to customize how root motion affects the GameObject.
Unity
void OnAnimatorMove() {
    // Custom root motion handling
    transform.position += animator.deltaPosition;
    transform.rotation *= animator.deltaRotation;
}
Sample Program

This script enables root motion on the Animator. The character moves exactly as the animation dictates without extra code.

Unity
using UnityEngine;

public class RootMotionExample : MonoBehaviour {
    Animator animator;

    void Start() {
        animator = GetComponent<Animator>();
        animator.applyRootMotion = true;
    }

    void Update() {
        // No manual movement needed, animation moves the character
    }
}
OutputSuccess
Important Notes

Root motion only works if the animation clip has movement in its root bone.

Disabling root motion means you must move the character manually in code.

Use OnAnimatorMove to fine-tune or combine root motion with code movement.

Summary

Root motion lets animations control character movement for natural results.

Enable it by setting applyRootMotion to true on the Animator.

You can customize root motion by overriding OnAnimatorMove.