What if your character's feet never slide again, just by letting the animation do the moving?
Why Root motion in Unity? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you are making a game where a character walks and runs. You try to move the character by changing its position in code while playing animations separately. It feels like you have to control two things at once: the animation and the movement.
Manually syncing the character's movement with its animation is tricky and slow. If you move the character too fast or too slow, the feet might slide on the ground or look unnatural. Fixing this by hand takes a lot of time and can still look wrong.
Root motion lets the animation itself control the character's movement. The character moves exactly as the animation shows, so the feet stay planted naturally. This removes guesswork and makes movement smooth and realistic without extra coding.
character.position += direction * speed * Time.deltaTime;
animator.Play("Run");animator.applyRootMotion = true;
animator.Play("Run");Root motion makes character movement perfectly match animations, creating smooth and believable actions with less effort.
In a game, when a character climbs stairs or jumps, root motion ensures the movement matches the animation exactly, so the character doesn't slide or float unrealistically.
Manually syncing movement and animation is hard and error-prone.
Root motion lets animations drive the character's movement automatically.
This creates smooth, natural motion with less coding work.
Practice
applyRootMotion on an Animator component do in Unity?Solution
Step 1: Understand the role of applyRootMotion
SettingapplyRootMotionto true allows the animation's movement data to move the character automatically.Step 2: Compare with other options
Other options describe disabling animations or ignoring root motion, which is incorrect.Final Answer:
It lets the animation control the character's movement automatically. -> Option BQuick Check:
applyRootMotion true = animation controls movement [OK]
- Thinking applyRootMotion disables animations
- Confusing root motion with scripted movement
- Assuming it resets position every frame
Solution
Step 1: Recall the correct property name
The Animator component uses the propertyapplyRootMotionto enable root motion.Step 2: Check syntax correctness
Onlyanimator.applyRootMotion = true;is valid C# syntax and correct property usage.Final Answer:
animator.applyRootMotion = true; -> Option AQuick Check:
Correct property = applyRootMotion [OK]
- Using incorrect property names like rootMotion
- Trying to call methods instead of setting properties
- Syntax errors like missing semicolons
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?Solution
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.Step 2: Understand the movement effect
This means horizontal movement (X and Z) follows animation, but vertical movement stays unchanged.Final Answer:
The character moves following the animation's horizontal root motion but keeps its original vertical position. -> Option DQuick Check:
Y position unchanged, horizontal moves with root motion [OK]
- Assuming full 3D root motion is applied
- Ignoring the line that keeps Y position fixed
- Thinking character stays still
void OnAnimatorMove() {
transform.position = animator.rootPosition;
transform.rotation = animator.rootRotation;
}
But the character does not move as expected. What is the likely problem?Solution
Step 1: Check root motion enabling
Root motion only works ifapplyRootMotionis true on the Animator component.Step 2: Understand OnAnimatorMove usage
UsingOnAnimatorMoveto override root motion is valid, but it requiresapplyRootMotionenabled.Final Answer:
The Animator's applyRootMotion property is not enabled. -> Option AQuick Check:
applyRootMotion must be true for root motion [OK]
- Forgetting to enable applyRootMotion
- Thinking base.OnAnimatorMove() is required
- Believing transform can't be set in OnAnimatorMove
OnAnimatorMove to achieve this?Solution
Step 1: Understand the goal
You want horizontal movement from root motion but vertical movement controlled by physics (like gravity velocity).Step 2: Combine root motion with vertical velocity
OverrideOnAnimatorMoveto set horizontal position from root motion and add vertical velocity manually to Y position.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.Final Answer:
Set transform.position to animator.rootPosition and add vertical velocity manually. -> Option CQuick Check:
Combine root motion horizontal + manual vertical velocity [OK]
- Keeping Y position unchanged ignores physics
- Ignoring vertical velocity causes unnatural movement
- Not overriding OnAnimatorMove loses control
