Bird
Raised Fist0
Unityframework~10 mins

Root motion in Unity - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Root motion
Animator plays animation clip
Animation contains root motion data
Extract root motion delta position & rotation
Apply root motion to GameObject transform
GameObject moves/rotates in scene
Next frame
Root motion means the animation moves the character by changing its position and rotation, not just playing visuals.
Execution Sample
Unity
void OnAnimatorMove() {
    transform.position += animator.deltaPosition;
    transform.rotation *= animator.deltaRotation;
}
This code applies the root motion delta from the animation to the GameObject's position and rotation each frame.
Execution Table
StepAnimator deltaPositionAnimator deltaRotationTransform.position beforeTransform.rotation beforeActionTransform.position afterTransform.rotation after
1(0.1, 0, 0)Quaternion.Euler(0, 5, 0)(0, 0, 0)Quaternion.Euler(0, 0, 0)Apply deltaPosition and deltaRotation(0.1, 0, 0)Quaternion.Euler(0, 5, 0)
2(0.2, 0, 0)Quaternion.Euler(0, 10, 0)(0.1, 0, 0)Quaternion.Euler(0, 5, 0)Apply deltaPosition and deltaRotation(0.3, 0, 0)Quaternion.Euler(0, 15, 0)
3(0, 0, 0)Quaternion.identity(0.3, 0, 0)Quaternion.Euler(0, 15, 0)No movement in animation(0.3, 0, 0)Quaternion.Euler(0, 15, 0)
4(0.15, 0, 0)Quaternion.Euler(0, -5, 0)(0.3, 0, 0)Quaternion.Euler(0, 15, 0)Apply deltaPosition and deltaRotation(0.45, 0, 0)Quaternion.Euler(0, 10, 0)
5(0, 0, 0)Quaternion.identity(0.45, 0, 0)Quaternion.Euler(0, 10, 0)No movement in animation(0.45, 0, 0)Quaternion.Euler(0, 10, 0)
💡 Animation frames end or no more root motion data to apply
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5
transform.position(0, 0, 0)(0.1, 0, 0)(0.3, 0, 0)(0.3, 0, 0)(0.45, 0, 0)(0.45, 0, 0)
transform.rotationQuaternion.Euler(0, 0, 0)Quaternion.Euler(0, 5, 0)Quaternion.Euler(0, 15, 0)Quaternion.Euler(0, 15, 0)Quaternion.Euler(0, 10, 0)Quaternion.Euler(0, 10, 0)
animator.deltaPosition(0, 0, 0)(0.1, 0, 0)(0.2, 0, 0)(0, 0, 0)(0.15, 0, 0)(0, 0, 0)
animator.deltaRotationQuaternion.identityQuaternion.Euler(0, 5, 0)Quaternion.Euler(0, 10, 0)Quaternion.identityQuaternion.Euler(0, -5, 0)Quaternion.identity
Key Moments - 3 Insights
Why does the GameObject move even though we only play an animation?
Because the animation contains root motion data that changes position and rotation, which we apply to the GameObject's transform as shown in the execution_table steps.
What happens if animator.deltaPosition is zero but deltaRotation is not?
The GameObject will rotate but not move in position.
Why do we multiply transform.rotation by deltaRotation instead of adding?
Rotations are combined by multiplication of quaternions to keep correct orientation, as shown in the execution_table rotation updates.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is transform.position after step 2?
A(0.2, 0, 0)
B(0.3, 0, 0)
C(0.1, 0, 0)
D(0, 0, 0)
💡 Hint
Check the 'Transform.position after' column in row for step 2.
At which step does the animator.deltaPosition have no movement?
AStep 3
BStep 1
CStep 4
DStep 2
💡 Hint
Look at the 'Animator deltaPosition' column for zero vector.
If we skip applying animator.deltaRotation, what happens to transform.rotation after step 1?
AIt becomes Quaternion.identity
BIt becomes Quaternion.Euler(0, 5, 0)
CIt stays at Quaternion.Euler(0, 0, 0)
DIt becomes Quaternion.Euler(0, 10, 0)
💡 Hint
Refer to how transform.rotation changes by multiplying deltaRotation in execution_table.
Concept Snapshot
Root motion means the animation moves the character's position and rotation.
Use OnAnimatorMove() to apply animator.deltaPosition and animator.deltaRotation.
Apply deltaPosition by adding to transform.position.
Apply deltaRotation by multiplying transform.rotation.
This makes the GameObject move naturally with the animation.
Full Transcript
Root motion in Unity means the animation clip contains movement data that changes the GameObject's position and rotation. Instead of just playing visuals, the animation moves the character in the scene. The key method is OnAnimatorMove(), where we take the animator's deltaPosition and deltaRotation and apply them to the GameObject's transform. This is done by adding deltaPosition to transform.position and multiplying deltaRotation with transform.rotation. The execution table shows step-by-step how these values change each frame, moving and rotating the GameObject. Beginners often wonder why the object moves without explicit code; it's because of root motion data in the animation. Also, rotations combine by multiplication, not addition, to keep orientation correct. Understanding this helps create smooth, realistic character movement driven by animations.

Practice

(1/5)
1. What does enabling applyRootMotion on an Animator component do in Unity?
easy
A. It resets the character's position to the origin every frame.
B. It lets the animation control the character's movement automatically.
C. It makes the character move only by script, ignoring animations.
D. It disables all animations on the character.

Solution

  1. Step 1: Understand the role of applyRootMotion

    Setting applyRootMotion to true allows the animation's movement data to move the character automatically.
  2. Step 2: Compare with other options

    Other options describe disabling animations or ignoring root motion, which is incorrect.
  3. Final Answer:

    It lets the animation control the character's movement automatically. -> Option B
  4. Quick Check:

    applyRootMotion true = animation controls movement [OK]
Hint: Remember: applyRootMotion true means animation moves character [OK]
Common Mistakes:
  • Thinking applyRootMotion disables animations
  • Confusing root motion with scripted movement
  • Assuming it resets position every frame
2. Which of the following is the correct way to enable root motion in a Unity Animator component via script?
easy
A. animator.applyRootMotion = true;
B. animator.rootMotion = true;
C. animator.enableRootMotion(true);
D. animator.setRootMotion(true);

Solution

  1. Step 1: Recall the correct property name

    The Animator component uses the property applyRootMotion to enable root motion.
  2. Step 2: Check syntax correctness

    Only animator.applyRootMotion = true; is valid C# syntax and correct property usage.
  3. Final Answer:

    animator.applyRootMotion = true; -> Option A
  4. Quick Check:

    Correct property = applyRootMotion [OK]
Hint: Use applyRootMotion property exactly as named [OK]
Common Mistakes:
  • Using incorrect property names like rootMotion
  • Trying to call methods instead of setting properties
  • Syntax errors like missing semicolons
3. Given this code snippet in a Unity script attached to a character:
void OnAnimatorMove() {
    Vector3 rootPos = animator.rootPosition;
    rootPos.y = transform.position.y;
    transform.position = rootPos;
}
What is the effect of this code on the character's movement?
medium
A. The character moves only vertically according to the animation.
B. The character moves exactly as the animation's root motion in all directions.
C. The character ignores root motion and stays still.
D. The character moves following the animation's horizontal root motion but keeps its original vertical position.

Solution

  1. Step 1: Analyze the code's position adjustment

    The code sets the character's position to the animation's root position but keeps the original Y (vertical) position.
  2. Step 2: Understand the movement effect

    This means horizontal movement (X and Z) follows animation, but vertical movement stays unchanged.
  3. Final Answer:

    The character moves following the animation's horizontal root motion but keeps its original vertical position. -> Option D
  4. Quick Check:

    Y position unchanged, horizontal moves with root motion [OK]
Hint: Check which axes are changed in root motion code [OK]
Common Mistakes:
  • Assuming full 3D root motion is applied
  • Ignoring the line that keeps Y position fixed
  • Thinking character stays still
4. You wrote this code to apply root motion in Unity:
void OnAnimatorMove() {
    transform.position = animator.rootPosition;
    transform.rotation = animator.rootRotation;
}
But the character does not move as expected. What is the likely problem?
medium
A. The Animator's applyRootMotion property is not enabled.
B. OnAnimatorMove should not be used for root motion.
C. You must call base.OnAnimatorMove() inside the method.
D. The transform cannot be set inside OnAnimatorMove.

Solution

  1. Step 1: Check root motion enabling

    Root motion only works if applyRootMotion is true on the Animator component.
  2. Step 2: Understand OnAnimatorMove usage

    Using OnAnimatorMove to override root motion is valid, but it requires applyRootMotion enabled.
  3. Final Answer:

    The Animator's applyRootMotion property is not enabled. -> Option A
  4. Quick Check:

    applyRootMotion must be true for root motion [OK]
Hint: Always enable applyRootMotion to use root motion overrides [OK]
Common Mistakes:
  • Forgetting to enable applyRootMotion
  • Thinking base.OnAnimatorMove() is required
  • Believing transform can't be set in OnAnimatorMove
5. You want your character to move with root motion but only apply horizontal movement from the animation, while controlling vertical movement via physics (gravity). How should you modify OnAnimatorMove to achieve this?
hard
A. Set transform.position to animator.rootPosition but keep transform.position.y unchanged.
B. Set transform.position to animator.rootPosition and ignore vertical velocity.
C. Set transform.position to animator.rootPosition and add vertical velocity manually.
D. Do not override OnAnimatorMove; use applyRootMotion only.

Solution

  1. Step 1: Understand the goal

    You want horizontal movement from root motion but vertical movement controlled by physics (like gravity velocity).
  2. Step 2: Combine root motion with vertical velocity

    Override OnAnimatorMove to set horizontal position from root motion and add vertical velocity manually to Y position.
  3. Step 3: Choose the correct approach

    Set transform.position to animator.rootPosition and add vertical velocity manually. describes adding vertical velocity manually, which matches the goal.
  4. Final Answer:

    Set transform.position to animator.rootPosition and add vertical velocity manually. -> Option C
  5. Quick Check:

    Combine root motion horizontal + manual vertical velocity [OK]
Hint: Add vertical velocity manually when overriding root motion [OK]
Common Mistakes:
  • Keeping Y position unchanged ignores physics
  • Ignoring vertical velocity causes unnatural movement
  • Not overriding OnAnimatorMove loses control