0
0
Unityframework~30 mins

Root motion in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Root Motion Control in Unity
📖 Scenario: You are creating a simple character animation in Unity. You want to control the character's movement using root motion from the animation clip.
🎯 Goal: Build a Unity script that enables and disables root motion on a character's Animator component, and observe how it affects the character's movement.
📋 What You'll Learn
Create a GameObject with an Animator component
Write a script to toggle root motion on the Animator
Use a boolean variable to control root motion
Print the current root motion status to the console
💡 Why This Matters
🌍 Real World
Root motion is used in games to make character movement more natural by letting animations control position changes.
💼 Career
Understanding root motion is important for game developers and animators working with Unity to create smooth character animations.
Progress0 / 4 steps
1
Create an Animator variable
Create a public variable called animator of type Animator inside a new C# script called RootMotionController.
Unity
Need a hint?

Declare a public Animator variable to link the Animator component from the Unity Editor.

2
Add a boolean to control root motion
Add a public boolean variable called useRootMotion to the RootMotionController script.
Unity
Need a hint?

This boolean will let you turn root motion on or off from the Unity Editor.

3
Set Animator root motion in Update
Inside the Update() method, set animator.applyRootMotion to the value of useRootMotion.
Unity
Need a hint?

Use the Update method to continuously apply the root motion setting each frame.

4
Print root motion status
Add a Debug.Log statement inside Update() to print "Root motion is enabled" when useRootMotion is true, and "Root motion is disabled" when false.
Unity
Need a hint?

Use an if-else statement to print the status based on the boolean value.