Journal 67 — Unity “The Great Fleece”, Add Character Model and Animations

Chris Nielsen
4 min readAug 12, 2021

--

Objective: To update our placeholder Player game object with prefab character and animations

In “The Great Fleece”, we just fixed the camera views with a primitive capsule for the Player. Now we want to swap out the primitive with a prefab character and add the animations.

To start, we can fix the Player game object by turning off the mesh renderer, dragging the Darren 3D prefab, and making adjustments to the scale and colliders.

Now let’s see how this looks in Playmode.

Let’s add the animator controller to correctly animate the player.

If you doubleclick on the Darren animator controller, that brings up the Animator window, and you can drag in the three pre-made animations. By dragging in the “Idle” animation, that will be designated the default state.

You can see the slight movement of idle animation in Playmode, and the Animator window shows the idle animation running.

Walk Animation

Now we need to implement the Walk to Idle and Idle to Walk transitions when Darren is moving or stops. To start, we need to make transitions between Idle and Walk, and also add a Bool parameter that we can update in code.

We need to also add a transition condition. From Idle to Walk, the bool we created “Walk” should be true, and from Walk to Idle, “Walk” should be false.

Now we need to update the code on the Player to switch from Idle to Walk animation. We can look up on Unity documentation the Animator component, which requires updates to add a handle to the Animator on the Player, add a reference to the Animator component which is a child of the Player, and use the Animator.SetBool function to set the Walk animation to true.

You can see this walk animation in action.

Idle Animation

Now let’s update the animations to transition from walking back to idle. We can do this by calculating the distance between the Player’s location and destination, and if the Player is within 1 unit of the destination, we can transition to the Idle animation.

Since hitInfo.point is a local variable, we can’t access it. So we can create a global variable and set this equal to hitInfo.

Finally, we can see the results of Walk and Idle animations.

Thank you for your time!

--

--

Chris Nielsen
Chris Nielsen

Written by Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

No responses yet