Unity’s new input system is out of preview, and it’s here to stay! This package simplifies how we can handle multiple forms of player input! In this tutorial, we will learn to move animated characters using root motion and how to use the new input system to move them with a gamepad! I’m Nicky. This channel is iHeartGameDev! Let’s get started! We’ll begin today by downloading idle, walk, and run animations from Mixamo.com. If you want a thorough explanation of the settings, check out my previous tutorial covering exporting from Mixamo.

But the main difference today is that we will leave the “in-place” checkbox unchecked! Opening a brand new Unity project, we’ll add a plane to the scene along with colorful material. Dragging our downloaded FBX files into the project, we will convert our characters to humanoid and duplicate the animations attached to each file. We will select the “loop time” checkbox for each duplicate animation so that the animation will continuously repeat. Cool. Next, let’s drag our idle fbx file into the scene hierarchy and the character to the scene. Now, to get our character moving using a promotion, we will need to add components directly to this character.

Animator Component

Because we converted our character to humanoid, an Animator component has already been added, and the character’s avatar was generated and applied. The avatar is Unity’s remapped bone-hierarchy, and it automatically assigns the root-bone for root-motion and gives us access to toolslike animation retargeting. Pressing on “Add Component,” we will type“New Script” and name the script “character movement.” We should now have an animator component and script attached to the character. Double-clicking on the animator controller, we’ll open the animator window. Let’s add our downloaded animations by dragging the duplicate copies starting with the idle animation. The idle animation should be highlighted in orange, meaning that it’s the default animation state. How do we get the character moving? Simple! We can set up transitions between our animations! And each transition will be controlled by parameters. Let’s create these now.

We’ll create two true/false boolean parameters: “walking” and “isRunning.” Then we’ll add transitions from the idle state to the waking state and the waking state back to the idle state, each being controlled by the “walking” parameter. We’ll set the condition to be “true” for the transition from the idle to the walking state and “false” to transition from the waking state to the idle state. We’ll toggle off “Has Exit Time” so the animations will transition when the parameters change.” We can repeat this from the walking state to the running state, except we’ll use the isRunning boolean for the parameter controlling these transitions. Testing our work in play mode, we’ll see some unexpected results when we activate the “walking” boolean. Our character will begin walking but not in a straight line. This is where we begin to talk about RootMotion. My understanding of root motion is that the character’s movement in world space is “baked” or “recorded” into the animation. What this means is that the character as a whole is moving in the X, Y, or Z-axis. Applying root motion can be as easy as checking a box, as is required with the animator component’s “Apply root motion” checkbox.

Desired Results

But sometimes, we need to modify the animation for our desired results. Selecting our Run FBX, we’ll have access to settings that begin with “Root Transform.” Let’s take a look at each sub-setting! Bake Into Pose essentially means that the animation will not impact the game object: the rotation, the height, or the changes on the X/Z axis. The green/red indicator is whether Unity recommends that we use the Bake Into Pose option or not. These, respectively, will adjust the clip to face the body’s forward vector or stay in line with the chosen root transform. We can also manually apply an Offset to each and adjust the direction ourselves. And “Original” will use the offset recorded from the imported animation clip. To fix our running issue, we need to switch to “Original” for root rotation and apply it into the pose! Ok, we are at the point where we need to grant the player control of our character. Let’s take a look at the New Input system! We will need first to install the package. No big deal.

Let’s press “window,” “package manager,” and find and select “Input System.” We can install the package and, when prompted, we can restart Unity to disable the old input system and activate the new one! We will start using this new input system by creating a new InputAction asset in the project tab. Right-clicking in the project window, we will go to “Create” and select “Input Actions” towards the bottom. We can rename this asset to “PlayerInput.” Double-clicking on the asset, a completely new input actions window will open. This is the new interface to handle player input. In this window, we’ll see three sections: Action Maps, Actions, and Properties, all of which are interconnected. Action maps can be seen as collections or containers for a list of actions. Each action is some input from the player. And the properties section is where we designate additional details about the input. Let’s create our first Action map as an example. Pressing the plus button, we will title the action Map “CharacterControls.” Now, we can create actions that will be stored within the CharacterControls action map. Let’s title this new action, “Movement.” When creating a new Action. Unity will also generate an empty binding associated with it.

Final Word

A binding is the “player input” that we get to select for an Action. In our example, “movement,” we will select the left joystick. The Properties Section references whatever is actively selected in the Actions section. If we press on the “Movement” Action, the properties panel will display 3 menus: Action, Interactions, and Processors. Action has a single dropdown menu titled: “Action Type.” Here, we have three options: Button, Value, or Pass-Through. Value is the most robust of the action types.