Day 100: Character Animation Part 3

Objective: Add a run animation to the character.

We have downloaded an Idle animation and implemented it. Now it is time to do a run animation. We will start off at Mixamo and download a running animation. When we go to Mixamo, just search for run.

When we find one we one we will make sure In Place is check and then just click download, change format to FBX for Unity. Make sure we have “With Skin” as well.

Once download import into your project. When it is finished, select the asset and set the Rig animation Type to Humanoid.

Next we will duplicate the Animation file and move into the animation folder.

Next we will drag the duplicated animation into the Animator window.

We will use transitional lines from Offensice Idle once speed is greater than .1 and back to Offensive Idle once speed is less than .1. We do this by creating a Float Parameter named Speed.

We need to select the transition lines and look in the inspector window. We need to uncheck “Has Exit Time” and reduce the “Transition Duration”. We will do this for both of the transitional lines we created.

Now to get the code to tell the animator to start the Run animation. In our player script we will need a reference to our animator that is on our child component. We will also run a null check.

To give the animator float a value from the script, we will need to know where we are applying that value from. Where we check for Input is the value we will use to supply the animator. We will call _anim.SetFloat(“Speed”, Mathf.abs(horizontal);. We will use Mathf.abs() to return the absolute value of horizontal. If we go left, horizontal will return -1 and to use the animator float value, we will need a positive number.

Now our animator walks back and forth! Tomorrow we will cover how to flip the character to face the right direction.

Thank you for reading and have a wonderful day!!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tyler Smallwood

Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer