0
0
Unityframework~10 mins

Root motion in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable root motion on the Animator component.

Unity
Animator animator = GetComponent<Animator>();
animator.[1] = true;
Drag options to blanks, or click blank then click option'
AapplyRootMotionEnabled
BapplyRootMotion
CapplyRootMotionFlag
DapplyRootMotionTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property name.
Trying to set root motion on the wrong component.
2fill in blank
medium

Complete the code to override root motion in the Animator by implementing the correct method.

Unity
void [1]() {
    // Custom root motion handling
}
Drag options to blanks, or click blank then click option'
AOnRootMotionApply
BOnRootMotionUpdate
COnAnimatorRoot
DOnAnimatorMove
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in Unity's Animator callbacks.
Trying to override root motion in Update() instead.
3fill in blank
hard

Fix the error in the code to correctly apply root motion delta to the transform.

Unity
void OnAnimatorMove() {
    transform.position += [1];
    transform.rotation *= animator.deltaRotation;
}
Drag options to blanks, or click blank then click option'
Aanimator.deltaPosition
Banimator.rootPosition
Canimator.positionDelta
Danimator.motionDelta
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property like rootPosition or motionDelta.
Confusing deltaPosition with transform.position.
4fill in blank
hard

Fill both blanks to create a dictionary that maps animation clip names to their root motion curves.

Unity
Dictionary<string, AnimationCurve> rootMotionCurves = new Dictionary<string, AnimationCurve>() {
    { [1], [2] }
};
Drag options to blanks, or click blank then click option'
A"Run"
BrunCurve
C"Jump"
DjumpCurve
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of strings for keys.
Swapping the key and value positions.
5fill in blank
hard

Fill all three blanks to correctly update the Animator's root motion position and rotation in OnAnimatorMove.

Unity
void OnAnimatorMove() {
    Vector3 rootPos = transform.position + [1];
    Quaternion rootRot = transform.rotation * [2];
    transform.SetPositionAndRotation(rootPos, [3]);
}
Drag options to blanks, or click blank then click option'
Aanimator.deltaPosition
Banimator.deltaRotation
CrootRot
Dtransform.rotation
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform.rotation instead of the combined rootRot.
Not adding deltaPosition to current position.