Day #50: Player Animations

Today was the 50th day of my journey and again I was happy to extend my knowledge on this road. I actually did not know that there was a free website that we can use to gather perfect animation for pre-rigged game assets.

Mixamo is a website created by Adobe that provides ready to use animations for our characters — for free. It is also possible to upload our character and visualize the selected animation on the right side.

You can search for any animation of your desire, here’s the results for Idle:

Once you select it, click on download and make sure to set the Format to “FBX for Unity”.

Drag and drop the downloaded fbx file to your project view.

It is crucial to update the Rig of the animation that we have downloaded from Mixamo according to our usage. In this game, we are using a humanoid character for the animation. Selec the downloaded animation and from the inspector select the Rig and change the Animation Type to “Humanoid” — and apply.

Now, we are ready to work on the animation.

At first, you will realize that you will not be able to edit the animation that you have imported.

To solve this, simply duplicate the animation (CTRL +D); which will create a duplicate outside of the folder you have just imported.

Now, we can work on the duplicated one without any problem. So buckle up! Organize your scene and do not forget to create an Animator Controller for the player. Just drag and drop the animation to the Animator window.

And here’s our Happy character: (do not forget to set the loop to true).

In this game, we will also require more animations like run, jump and grab. Since Mixamo was a new thing for me, I would like to also remind you that do not forget to check the “In Place” checkbox before downloading an animation (for the animations that player is user controlled), so that we will manipulate the actual movement, not the animation itself.

Some animations are not provided with an In Place checkbox. In these cases, we might be able to use it “In Place” by making some arrangements in Unity. For instance, the jumping animation did not have an “In Place” checkbox with it. And that actually fixed it

Since I have already covered some Animation articles, I will skip the detail. Briefly, we need to add a parameter to set the animation state of our character. It’s actually up to us to decide, an easy solution might use a float variable that checks the horizontal input.

If you face a problem that your character actually rotates on the run animation, you might check the Animator component and uncheck the “Apply Root Motion” option — which was the case in the game.

Character rotates slightly on each run

Additionally, it really did not look so well once I hitted to any horizontal Input buttons. It was like lagging. I did not know or used GetAxisRaw up to this day. As we know, Input.GetAxis returns a float value from the range -1 to 1, where the value increments at a pace as we keep on pressing a button on the triggering axis.

On the other side, GetAxisRaw returns an integer value of -1, 0 or 1 rather than a float. The problem on the first run was that our character was lagging because it took some time to reach to 0.1 for the float value (0.1 is the value that we have set for the run animation to be triggered). Now, it returns a 1 simultaneously we press a triggering button.

You can also observe that we change the rotation of the character according to the input gathered. Here’s the result:

Jump animation is only used while running, so there’s no mistake on that. Looks good tho’ :).

Unity Developer