Home and Learn: Games Programming Course


Unity 3D: Add a First Person Controller

Added May 2025, Unity 6, using URP

In this section, you'll learn the mechanics of first person shooter games. We'll have a character that can walk around and shoot things, and we'll have an enemy zombie that can attack us and cause damage. We'll tackle animations, health scripts, gun sights, skyboxes, prefabs, and a whole lot more. The short video below shows you what you will be creating in this section:

 

In the next lesson, you'll learn how to build that scene in the video above using free game assets. But this is a big section, so let's get started. We're going to have something called a first person controller. This will be our player. We'll download a ready-made one from the Unity Asset store.

 

New Unity Project using the Universal Render Pipeline

So, start up your Unity Hub, if you haven't already. From the Unity Hub, click the New Project button. In the templates area, select the Universal 3D template. This uses the Universal Render Pipeline. (The other options are the Built-In Render Pipeline, and the High Definition Render Pipeline.)

Give your project a name in the Project Name box. We called ours First Person Shooter. Then click Create Project:

Unity Hub showing a project being created using the Universal Render Pipeline.

 

Install the First Person Controller from the Unity Asset Store

We need to download a First Person Character Controller. This will have all the movement scripts already attached to it, so we won't have to write any code for our character to do things like run, walk, jump, etc.

Unity themselves have a First Person Character Controller we can use. From the menus at the top of Unity 6, click Window > Asset Store. Once the Asset Store loads in your browser, go to this page:

https://assetstore.unity.com/packages/essentials/starter-assets-firstperson-updates-in-new-charactercontroller-pa-196525

If the link no longer works, type the following into the Asset Store search box:

Starter Assets - FirstPerson

Click the button on the Assets Store page to download and add the controller to your project. The Unity Package Manager should open for you:

Unity Package Manger with Starter Assets being imported

Click the Download button. (If you have already downloaded the asset, it will say Import, as in the image above).

Once you install, you'll see this box:

Starter Game Assets being imported into a Unity project

Import the assets and your Unity Project area should look like:

Unity 3D Project folder with game assets imported

Move into the following folder:

Assets > StarterAssets > Environment > Art > Models

Drag and drop the Ground_Mesh object into your scene:

A flat ground mesh being dragged into a Unity 3D scene

With the Ground_Mesh selected in your Hierarchy (you can rename it to Ground) have a look at the Inspector on the right. Click the three tiny dots in the top right and select Reset from the menu that appears (It will reset the position to all zeros):

Unity 3D Inspector showing the reaet option

Reset menu, Unity 6

Your player would fall through this mesh, however, because it doesn't have a collider attached. So, with the Ground selected in the Hierarchy on the left, have a look at the Inspector on the right. Click the Add Component button. Type mesh in the search box. Double click the Mesh Collider item:

Adding a Mesh Collider component to a ground game object in Unity 3D

 

Add the First Person Controller (the Player) to the Unity Scene

Now let's add our player to the scene.

Move inside of the following folder:

Assets > StarterAssets > FirstPersonController > Prefabs

Locate the prefab called PlayerCapsule:

A folder showing a first person controller prefab in Unity 6

Drag and drop it onto your Ground object in the scene. In the Hierarchy on the left of Unity, right-click your capsule and rename it to Player:

Dragging a first person controller prefab onto a Unity scene

Once you have dragged the first person controller into your scene, it should be ready to go!

Start your game and you should find that you can walk around. Press the WSAD keys to walk around (or the arrow keys). Press the spacebar to jump. Hold down the left SHIFT key to run.

One thing you will notice is that the camera is static - it doesn't move with the player. Let's fix that.

 

Unity First Person Controller Camera Setup

In the Project area at the bottom of Unity, open the following folder again:

Assets > StarterAssets > FirstPersonController > Prefabs

Notice that there are two blue cubes. These are camera prefab objects, one called MainCamera, and one called PlayerFollowCamera:

Camera prefabs

We'll need both of these. So drag the PlayerFollowCamera to the Hierarchy first:

Dragging a Player Follow camera into the Unity Hierarchy

With the PlayerFollowCamera selected in the Hierarchy, have a look at the Inspector on the right. Notice there is an empty slow to the right of Follow:

Unity Inspector showing a Follow option highlighted

Click the circle to the right of None (Transform) where the red arrow is pointing in the image above. You'll see this dialog box:

Select Transform options in a dialog box

Double click the Transform called PlayerCameraRoot. It will then get added to the Follow area:

A Camera transform added to a player in a Unity scene

To see where this PlayerCameraRoot is coming from, have a look at the Hierarchy on the left. Expand the Player object and you'll see it there:

The Player Hierarchy

We now need to add the Main Camera prefab, even though we have a Main Camera in our scene (we'll delete this).

So go back to this folder in the Projects Area of Unity:

Assets > StarterAssets > FirstPersonController > Prefabs

Drag and drop MainCamera into the Hierarchy:

Dragging a Main camera into the Unity Hierarchy

The Hierarchy should look like this:

The Unity Hierarchy with a Main Camera highlighted

With the MainCamera object selected, the Inspector will look like this:

The Unity Inpsector showing a camera highlighted

Notice the area highlighted with a red box in the image above. What's happening is that MainCamera is the brain, and it has set the second camera, the PlayerFollowCamera, to be it eyes, known as the Live Camera. So we don't need the other Main Camera, the one at the top. Select this camera in the Hierarchy. Then press the delete key on your keyboard to get rid of it. The Hierarchy should then look like this:

The Unity Hierarchy showing player and camera game objects

Try your game out again. You should now be able to walk around and the camera will follow.

One last thing you can do is to increase the size of the Player. Click on the Player in the Hierarchy. In the Inspector on the left, change the Scale values for X, Y and Z in the Transorm area at the top. Change them all to 1.8.

 

In the next lesson below, you'll build a better scene as we download some more free game assets.

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

 


Email us: enquiry at homeandlearn.co.uk