How to Create a Simple FPS in Unreal Engine 5

In this Unreal Engine 5 tutorial, you’ll create a simple first-person shooter while learning how to create a first-person character equipped with a gun, and you’ll learn how to apply damage to other actors in your game. By Ricardo Santos.

4.7 (3) · 2 Reviews

Download materials
Save for later
Share
You are currently viewing page 2 of 4 of this article. Click here to view the first page.

Setting the Default Pawn

Click Compile in the window’s top-left corner, and go back to the main editor. Before you click it, it shows a yellow circle with a question mark. After clicking, it should have a green circle instead, showing that the process was successful.

Behavior of the Compile button

Open the World Settings panel and locate the Game Mode section. Change Default Pawn Class to BP_Player.

Field defining the main character class.

Note: If you don’t have the World Settings panel, go to Settings in the top-right corner of the window and click World Settings.
Alternate way to get to the World Settings dialog.

Now, you’ll automatically use BP_Player when the game starts, and it’s placed automatically in the position of the Player Start asset. Press Play and use the W, A, S and D keys to move around. You may have to click the mouse inside the game window first to give that window the keyboard focus.

And now, you can move!

Next, you’ll create mappings for looking around.

Creating Look Mappings

Open Project Settings again. Create two more Axis Mappings called LookHorizontal and LookVertical.

Creating the axis mapping for the mouse events to handle looking horizontally.

Change the key for LookHorizontal to Mouse X.

Creating the axis mapping for the mouse events to handle looking vertically.

This mapping outputs a positive value when you move the mouse right and vice versa.

Next, change the key for LookVertical to Mouse Y.

Defining the mouse input, considered to the camera movement.

This mapping outputs a positive value when you move the mouse up and vice versa.

Now, you need to create the logic for looking around.

Implementing Looking

If a Pawn doesn’t have a Camera component, Unreal automatically creates a camera for you. By default, this camera uses the rotation of the controller.

Note: If you’d like to learn more about controllers, check out this tutorial on Artificial Intelligence.

Even though controllers are non-physical, they still have their own rotation. This means you can make the Pawn and camera face different directions. For example, in a third-person game, the character and camera don’t always face the same direction.

Camera look applied to a third-person game.

To rotate the camera in a first-person game, you just need to change the rotation of the controller. It’s pretty much the same process you did for movement — you just use rotations instead of translations.

Open BP_Player and create a LookHorizontal event.

Invoking the event to treat the horizontal component of the mouse look interaction.

To make the camera look left or right, you need to adjust the controller’s yaw. Create an Add Controller Yaw Input and connect it:

Add controller yaw input

When you move the mouse horizontally, the controller yaws left or right. Since the camera is using the controller’s rotation, it also yaws.

Repeat the process for LookVertical, replacing Add Controller Yaw Input with Add Controller Pitch Input.

Connecting the mouse vertical input to the camera rotation node.

If you test the game right now, you’ll notice that vertical looking is inverted. This means when you move the mouse up, the camera looks down. If you prefer non-inverted controls, add a Multiply operator and multiply Axis Value by -1. This inverts Axis Value and controller pitching.

Inverting the mouse look.

Click Compile, and then press Play. Use your mouse to start looking around.

Looking around in the game world.

Now that you’re done with movement and looking, it’s time to create a gun!

Creating the Gun

You know how when you create a Blueprint Class, you can select a parent class? Well, you can also select your own Blueprints as a parent. This is useful when you have different types of objects that share common functionalities or attributes.

Say you want to have multiple types of cars. You can create a base car class containing variables such as speed and color. You can then create children classes that use the base car class as a parent. Each child will also contain the same variables. Now, you have an easy way to create cars with different speed and color values.

Variations of a car blueprint.

You can use the same method to create guns. You just need to create a base class first.

Creating the Base Gun Class

Go back to the main editor, and create a Blueprint Class of type Actor. Name it BP_BaseGun, and double-click to open it.

Next, you’ll create variables to define the gun properties. To do that, go to the Variables section of the blueprint window, and click the + button on the top-right of the frame.

Creating variables on the UE5 blueprint window.

Create the following float variables:

  • MaxBulletDistance: How far each bullet can travel.
  • Damage: How much damage to apply when a bullet hits an actor.
  • FireRate: How long before the gun can shoot another bullet, measured in seconds.

Defining the variables of the gun blueprint class.

Note: The default value for each variable is zero, which is fine for this tutorial. However, if you wanted new gun classes to have a default value, you’d set it in BP_BaseGun.

Now, you need a physical representation of the gun. Click Add, type Static Mesh, select the component Static Mesh to add it to the blueprint class, and name it GunMesh.

Adding the gun mesh component to the gun class.

Don’t worry about selecting a static mesh now. You’ll do this in the next section when you create a child gun class. In this parent class, you just define that a gun must have a static mesh component that displays the gun geometry in the game.

Creating a Child Gun Class

Click Compile, and go back to the main editor. To create a child class, right-click BP_BaseGun and select Create Child Blueprint Class.

Creating a child object of the gun class.

Name it BP_Rifle, and then open it. Open the Class Defaults at the top-right of the window, and set the variable values:

  • MaxBulletDistance: 5000
  • Damage: 2
  • FireRate: 0.1

Changing class defaults for the BP_Rifle class.

This means each bullet can travel a maximum distance of 5000. If it hits an actor, it deals 2 damage. When firing consecutive shots, the duration between each shot will be at least 0.1 seconds.

Next, you need to specify which mesh the gun should use. Select the GunMesh component on the left side of the screen, and notice that the Details tab on the right side has changed its contents. Look for the Static Mesh section and use the drop-down menu to set it to SM_Rifle.

Setting the BP_Rifle mesh.

The gun is complete. Click Compile, and close BP_Rifle.

Next, you’ll create your own camera component to give you better control of camera placement. It’ll also allow you to attach and keep the gun in front of the camera.

Creating the Camera

Open BP_Player, and add a Camera component the same way you created the Static Mesh component of the BP_BaseGun class. Name it FpsCamera.

Creating the FPS camera.

The default position is a bit too low, which might make the player feel small. On the Details panel, set the location of FpsCamera to (X:0, Y:0, Z:90).

FPS Camera positioning.

By default, Camera components don’t use the controller’s rotation. To fix this, go to the Details panel and enable Camera Options ▸ Use Pawn Control Rotation.

Defining the gun rotation as being the same as the Pawn's.

Next, you need to define the gun’s location.