Creating a Controllable First-Person Character in Unity: A Beginner’s Guide

Charles Qi
4 min readMar 22, 2024

--

Prerequisites

  • Unity Hub with the latest version of Unity installed.
  • Basic familiarity with Unity’s interface.

Step 1: Prepare Your Scene

  1. Create a New Project: Start Unity Hub and create a new 3D project.
  2. Setup the Scene: Open your scene. Unity usually includes a default Main Camera and a Directional Light.

Step 2: Creating Your First-Person Character

  1. Add a Capsule: Go to GameObject > 3D Object > Capsule. This capsule will represent your player.
  2. Position Your Capsule: Place the capsule at a convenient location in your scene, such as the origin point (0, 0, 0).

Step 3: Setting Up the Camera

  1. Remove the Main Camera: Delete the default Main Camera in your scene as we will create a new camera that follows the capsule.
  2. Add a Camera to the Capsule: Select the Capsule in the Hierarchy, then go to GameObject > Camera to add a new Camera as a child object of the Capsule. This ensures the camera follows the capsule's movement.
  3. Adjust the Camera Position: With the Camera selected, adjust its position so that it’s where the “eyes” of the capsule would be. Usually, this means moving it upwards and slightly forward. Ensure the Camera is looking forward.

Step 4: Adding Movement

  1. Create a Script: Right-click in the Assets folder, choose Create > C# Script, and name it Controller.
  2. Edit the Script: Open the script and replace its contents with the following basic movement code:

This code allows for basic movement and unlocking the cursor with the Escape key.

Attach the Script to the Capsule: Drag and drop the Controller script onto the Capsule object in the Hierarchy.

Step 5: Adding Free Camera rotation.

  1. Create a New Script: Right-click in the Assets folder, select Create > C# Script, and name it CamRotate. This script will control the camera's rotation based on mouse movement.
  2. Edit the CamRotate Script: Open the script in your code editor and replace its contents with the following:

3. Attach the Script to the Camera:

  • In the Unity Editor, locate your first-person camera in the Hierarchy. This might be the main camera if you’re setting it up for a first-person view.
  • Drag the CamRotate script from your Assets folder onto the camera object in the Hierarchy. This can also be done by selecting the camera, then in the Inspector window clicking Add Component, searching for CamRotate, and adding it.

4. Assign the Player Body to the Script:

  • The script requires a reference to the player’s body to rotate it based on mouse movement horizontally. This is usually the capsule or character model that represents your player.
  • Click on the camera object in the Hierarchy to view its components in the Inspector.
  • Find the CamRotate component you just added. You'll see a field named Player Body.
  • Drag your player object (e.g., the capsule) from the Hierarchy and drop it into the Player Body field in the CamRotate script component.

Set up complete! Congratulations! You have created your first Controllable First-Person Character in Unity!

--

--