Adding Animations to A rigged Character In Unity

Using Mixamo Animations

James Lafritz
Dev Genius

--

Mixamo is an awesome place to get Characters and Animations for you game. They have Ready to Use Characters, You can Upload a model and get it automatically rigged. They also have Motion Captured Animations that you can use with any Humanoid Rigged character, It is best if the rig is set up the same as their rigging.

I already have a character that is Rigged to use animations from Mixamo. So I do not need a character. Currently they have 3 pages of characters.

Getting the Animations

They Have close to 2500 animations that you can chose from the best way to narrow down is to use the search bar to search.

I suggest Searching by the word pack to get a pack of animations that fit your needs. You can preview it in the window on the left. I think I am going to go with Action Adventure Pack As I like the Jump/Fall animation

Once you have the animation the you want Download it. There are several different options available. I do not need a character so I set the Pose to No Character (Use T-Pose or with Skin for better results), for the Format I am going to use the FBX for Unity.

Once it is downloaded I Extract the zip file into my project folder.

Next In Unity I make sure to set the Animation Type To Humanoid. To preview the Animation I dragged my Character onto the preview pane.

Using the Animations

I need to create a controller that I can use on my Player.

Now all I need to do is drag my animations on to the controller.

The Character Idles but the animation plays once. To Fix this I need to edit the animation an Loop the Time.

Root Motion

The Animations come with root motion in it. When I set the animator Speed to 1 the player takes off running.

This is great if I want the animations to control the player character motion which is what a lot of the character controllers do.

This is not the behavior that I want. I want everything controlled from within the Behavior. The Animator will only be used to display the animations.

To fix this I have 2 options. One option is to go back to Maximo and download the animations that I want to use with out root motion by selecting In Place option. This option is not available when downloading the Packs.

And using this animation

Of course I have to set the rig to Humanoid and the Animation to loop.

The other Option is to Set the Animator to not Apply Root Motion. Now even if the Animation has root motion in it it will not affect my character. This is what I want. Even if I choose to download individual animations without root motion applied, I may have some animations with root motion in it, like the Idle animation. Plus I will not have to download each individual motion.

Controlling the Animator

Now all I need to do is pass this information to the animator when the player is moving. For this I will be using a separate behavior for the Animations and ScriptableObject Variables. I installed my Core Framework using the Package Manager using add package from git git url https://github.com/JamesLaFritz/CoreFrameWork.git

I added the Player Animation Component to the Players Model.

I need a reference to the Animator to pass the need information to.

Right now the only Parameter I have in my Animator right now is Speed float, I will be adding more as I add more animations. I have to set the Speed float on the animator using the value of the ScriptableObject reference.

I create my Player Speed Variable and add it to the Player Animation Component.

Now change the value of the variable causes the Animator to play the correct animation.

Now I need to set this value in the Player Behavior. I set it to the absolute value of the move direction as the Animator is looking for a value greater then 0.1 to switch to the running animation and the Input is being set to -1, 0, 0r 1.

After setting the Parameter in the Inspector my Player now plays the correct animation when I move.

Animations For Running, Jumping, and Idle

I completed the Controller. It goes from Any State to the Running Jump if Is Jumping is true. I the switch back to the Idle or Running depending on the Speed when Is Jumping is false.

The Behaviors

In the Player Animation Behavior I added setting the Animator Is Jumping if the value of Is Jumping Bool Reference changes.

In the Player Behavior I set the Bool Reference to false if the controller is grounded and I set it to true if the Player jumps.

Now My Player can properly run and jump in the game.

--

--

Excited about changing my hobby into a new carer with GameDevHQ course.