Using the Unity Animation System (Game Dev Day 59)

Jack Leavey
3 min readJan 14, 2022

I added animations to the new model for the Player Character using the Animator window in Unity.

First off, I added an Animator component to the 3D model attached to my player gameobject.

Darren_3D is a child of the player gameobject.

Next, I opened up the animator window through:

Window>Animation>Animator

How to open the animator.
This is the animator window for the player character I am using.

I have 3 animations for the player character; Idle, Walk, and Throw.

The golden arrow from “Entry” to “Idle” means that “Idle” is the default animation to play. It will ALWAYS play unless it is told not to.

Next, I added two transitions between “Idle” and “Walk” indicated by the white lines. Turn off “Has Exit Time” or the entire current animation has to finish playing before the next one plays (leads to a delay in the animation).

Generally speaking, you do NOT want exit time.

We will come back to “Throw” later, as that needs some extra functionality before we can animate it.

Open the parameters tab inside the Animator Window.

The Parameters tab is located on the top right-side, next to the Layers tab.

I created a new bool parameter titled “Walk”. This bool will be used to determine if the idle animation should be playing (default) or the walk animation.

Now in the Player.cs script I added the Animator component in Start.

Line 15.

Next, I added line 30 to the existing movement input code.

So when you click to move, the “Walk” bool activates, changing the animation state to the walking animation!

Getting back to the “Idle” animation requires a little more work to do smoothly.

I created a new float variable and used Vector3.Distance to calculate the distance between the starting point of the player and the coordinates of the location they are traveling to. Once that value reaches 1 or lower, the “Walk” bool turns off, returning the player to the idle animation!

Animation switching in action!

--

--

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!