0
0
Unityframework~10 mins

Root motion in Unity - Step-by-Step Execution

Choose your learning style9 modes available
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.