Home and Learn: Games Programming Course

Unity - 3rd Person Controller

In this lesson, you'll create a third person character. It will look like this one in the video below:

In this lesson, you'll create a third person character. When you're done, it will look like this one in the video below:


(You'll learn how to swap out the character so that you can use any that takes your fancy.)

Let's get started.


Unity Starter Assets

Unity have recently released some new Starter Assets. These replace the old Standard Assets, which are now deprecated. The new ones consist of a first and third person controller. These uses the new input system.

So, start a new project. Add a Plane to the scene, and a material for the Plane.

Now we need to download the Starter Assets from Unity. Click on Window > Asset Store from the menus at the top of Unity. Then go to this page:

Unity Starter Assets

(Or type Starter Assets in the search bar at the top of the Asset Store.)

Download and install the Third Person Character Controller.

While you're on the asset store, let's download a sword. You can do a search for swords. But we went for the ones on this page:



Adding the Third Person Character

In the Project area at the bottom of Unity, have a look for a folder called Starter Assets. Expand the folder called ThirdPersonController, then click on the prefabs folder. You should see an item called PlayerArmature:

Unity Project area showing the Player Armature

To add the character to your scene, you could just drag and drop it. But there is another way. Click the Tools item on the menu at the top of Unity. From the Tools menu, select Starter Assets > Reset Third Person Controller Armature:

Starter Assets menu

You should now see a robot in your scene:

Default robot character showing in a Unity scene

Click the Play button at the top of unity. Use the WASD keys to move around (or the arrow keys). Press the spacebar and the robot will jump. Hold down the left shift key to run. Make sure to move your mouse around to get a feel for the way the camera works.

Of course, you probably don't want a robot. You want your own character. You'll learn how to swap it out shortly. For now, take a look at the way the cameras work. If you click on the Main Camera item in the Hierarchy, you'll see that it has a Cinemachine Brain component. Cinemachine is a cameras system that can be used to do all kinds of things, such as the Dolly tracking you see in complex cutscenes. You should find that there's an entry for Cinemachine added to the Game Object menu at the top of Unity:

Cinemachine menu

Also in the Hierarchy, notice the item called Player Follow Camera. When you click on this item, notice the Inspector on the right. It has a Cinemachine Virtual Camera component added. You can tweak the settings for your camera here:

Cinemachine settings for a camera

There's a lot of settings here. But try adjusting the ones highlighted in the image above, Camera Side and Camera Distance¸ and see what they do.


Swap out the Third Person Robot

Now let's swap out the robot for a character of your choosing. It's easy enough to do!

We'll get a model from Mixamo. So, head on over to this site:


We've already downloaded animations from this site in previous lessons. This time, we'll grab a character. If you haven't done so already, sign up for an account. You can, of course, use any character you like. But we're going to use one called Eve by 3D artist J Gonzales. So, click on the Characters links at the top and do a search for Eve.

The Eve 3D character on Mixamo

Download the FBX file to your computer (select with skin from the dropdowns). Once it's on your computer, drag and drop the FBX file into the project area of Unity. You can create a folder called EVE, like we've done. We'll place animations in here, as well. Click to select the file:

Unity Project area showing a FBX file

With the file selected, have a look at the Inspector on the right. Click the Rig tab at the top and switch the Animation Type from Generic to Humanoid. Set the Avatar Definition to Create From This Model. Then click the Apply button at the bottom:

Unity Inspector showing how to Rig a character

Now expand the eve item in the Projects area by clicking the arrow, circled in red below:

The 3D character avatar

Notice the item on the end. This is the Avatar that we'll need to replace the robot.

Now look at the Hierarchy on the left. Select the PlayerArmature item. The item text is blue. It's blue because it's a prefab. However, we'll need to delete the robot. This can't happen while it's still a prefab. However, you can unpack a prefab. So, right click on PlayerArmature. From the menu that appears, select Prefab > Unpack Completely:

Unity Prefab menu

When you unpack the prefab, the text for PlayerArmature will turn white, indicating it is no longer a prefab.

Expand the PlayerArmature item in the Hierarchy. Now expand the Geometry item. Click on the Armature_Mesh to select it:

Highlighting the player's armature

With the Armature_Mesh selected, press the delete key on your keyboard to get rid of it (or right-click and select Delete from the menu). Now drag and drop your Eve model onto the Geometry item to replace Armature_Mesh:

Swapping out the default character

With the eve_j_gonzales item still selected in the Hierarchy, have a look at the Inspector in the Hierarchy. Locate the Avatar item. Click the tiny circle indicated by the red arrow below:

The Avatar item in the Unity Inspector

Clicking the tiny circle brings up a Select Avatar box. Double-click the eve item from the list:

The Select Avatar dialogue box

The Avatar area should now read eve_j_gonzalesAvatar:

The Inspector showing the Avatar item

Still in the Hierarchy, click on the PlayerArmature item. In the Inspector, do the same - switch the Avatar to the eve one:

And that's it - you're ready to go! Play your game and you should see the eve character moving around instead of the robot, as in the short video below:



Placing a Sword in Eve's hand

We need to drill down in the Eve model in the Hierarchy. We're looking for right hand. So, expand the eve_j_gonzales item in the Hierarchy. You'll see items for Hips and Mesh. Expand the Hips item and then keep going through these items:

Right Shoulder
Right Arm
Right ForeArm
Right Hand

Player bones, right hand

Now right-click on RightHand. From the menu that appears, select Create Empty. Rename the empty object to SWORD. In the project area of Unity, drag and drop your sword onto the SWORD empty game object:

Placing a sword model in the character's hand

Select the Wakizashi item. The sword will be pointing up, so you'll need to reposition and rotate it. This is a little bit fiddly. But a rotation on the Y of 95 seems to work OK. For the X, Y and Z positions in the Inspector, we went for values of 0.13, 0.023, and -0.011. It looked like this in Scene view:

Positioning the sword in the 3D model's hand

It looks slightly misaligned, in the image above. However, when playing the game, it looks like this:

Eve 3D character with sword

Close enough! Now let's do the animations. For this, we'll need to hack the code a little, and add something to the input controller.


<--Back to the Unity 3D Course Contents Page

Email us: enquiry at homeandlearn.co.uk