Skip to main content
Unreal Engine 5 – Complete Beginner to Advanced Guide
CHAPTER 06 Intermediate

Player Movement and Input Systems

Updated: May 16, 2026
25 min read

# CHAPTER 6

Player Movement and Input Systems

1. Introduction

A game without interactivity is a movie. The core of game development is reading what the player is doing with their keyboard, mouse, or controller, and translating that into action on the screen. In this chapter, we will master Player Movement and Input Systems. We will learn how to read raw keyboard input, explore the three main ways to move an object in Unity (Transform, Rigidbody, and CharacterController), and write a simple script to make the camera follow the player.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Read keyboard and mouse input using Unity's Input class.
  • Move an object manually using transform.Translate.
  • Understand the critical importance of Time.deltaTime.
  • Move a physics-based object using Rigidbody.AddForce.
  • Understand the basics of a 3D camera follow script.

3. Reading Player Input

Unity has a built-in class called Input. It listens to your hardware every single frame.
  • Button Presses: Input.GetKeyDown(KeyCode.Space) returns true the exact frame you press the spacebar.
  • Axes (Smooth Input): Instead of checking specifically for the 'W' or 'A' keys, Unity uses "Axes".
  • Input.GetAxis("Horizontal") returns -1 if you press A (left) and 1 if you press D (right).
  • Input.GetAxis("Vertical") returns -1 for S (backward) and 1 for W (forward).
*The beauty of GetAxis is that it also automatically works with Xbox and PlayStation controller thumbsticks!*

4. Method 1: Transform Translation (Kinematic)

The simplest way to move an object is to manually change its coordinates.
csharp
123456789101112
public float speed = 5f;

void Update()
{
    float h = Input.GetAxis("Horizontal"); // A/D keys
    float v = Input.GetAxis("Vertical");   // W/S keys

    // Move along the X and Z axes
    Vector3 moveDirection = new Vector3(h, 0, v);
    
    transform.Translate(moveDirection * speed * Time.deltaTime);
}

What is Time.deltaTime? If you run Translate in Update, it runs every frame. If someone has a fast PC (144 FPS), the player will run twice as fast as someone on a slow PC (60 FPS). Multiplying by Time.deltaTime normalizes the speed to "meters per second," ensuring the game plays exactly the same on all computers!

5. Method 2: Rigidbody Movement (Physics)

If your player needs to bounce off walls, fall via gravity, or push heavy crates, you must use a Rigidbody. Instead of manually translating the position, you push the Rigidbody with forces.
csharp
1234567891011
public Rigidbody rb;
public float pushPower = 10f;

void FixedUpdate() // ALWAYS use FixedUpdate for Rigidbody physics!
{
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");
    
    Vector3 pushDirection = new Vector3(h, 0, v);
    rb.AddForce(pushDirection * pushPower);
}

6. Method 3: CharacterController (The Industry Standard)

Moving a Rigidbody feels "floaty" and slippery (like a car). For tight, snappy 3D platforming (like Mario or Master Chief), Unity provides the CharacterController component. It allows manual movement like Translate, but automatically stops you from walking through walls and helps you walk up stairs!

7. Camera Follow Basics

If the player runs forward, the camera needs to follow them.
  • The Bad Way: Making the Camera a "child" of the Player. If the player turns around or rolls, the camera will violently spin and make the player nauseous!
  • The Good Way: A C# script on the camera that copies the player's position, but adds an "Offset" so it stays slightly behind and above.
csharp
1234567
public Transform player;
public Vector3 offset = new Vector3(0, 5, -10);

void LateUpdate() // Runs right after Update, ensuring the player has finished moving first!
{
    transform.position = player.position + offset;
}

8. Visual Learning: The Input Pipeline

txt
123456789
[ Player Presses 'W' ]
         |
[ Input.GetAxis("Vertical") returns 1.0 ]
         |
[ Calculate: Vector3(0, 0, 1.0) * Speed * DeltaTime ]
         |
[ transform.Translate() applies movement ]
         |
[ Camera LateUpdate() follows the new position ]

9. Best Practices

  • Use SerializeField for References: When writing the Camera script, don't use GameObject.Find("Player") in the Update loop—it causes massive lag. Instead, use public Transform player; and drag the Player object into the slot in the Inspector before the game starts.

10. Common Mistakes

  • Applying DeltaTime to AddForce: You must multiply Translate by Time.deltaTime to fix framerate issues. However, if you are using Rigidbody.AddForce() inside FixedUpdate(), do NOT multiply by Time.deltaTime! FixedUpdate already runs on a perfectly locked timer, so adding DeltaTime to it will cause your math to break.

11. Mini Project: Create a Controllable 3D Player

Objective: Build a scene with a floor, a player, and movement code.
  1. 1. Create a 3D Object -> Plane (The Floor).
  1. 2. Create a 3D Object -> Cube (The Player).
  1. 3. Create a C# script named PlayerMovement.
  1. 4. Open the script and paste the Transform Translation code from Section 4.
  1. 5. Save the script and drag it onto the Cube.
  1. 6. Create a C# script named CameraFollow and paste the code from Section 7.
  1. 7. Attach CameraFollow to the Main Camera. Click the Camera, look at the Inspector, and drag the Cube into the empty "Player" slot.
  1. 8. Press Play and drive your cube around!

12. Practice Exercises

  1. 1. What built-in Unity variable must you multiply movement by to ensure your game speed is independent of the computer's framerate?
  1. 2. If you are applying physics forces to a Rigidbody, which specific update loop must you place the code in?

13. MCQs with Answers

Question 1

A programmer wants to check if the player pressed the "Spacebar" to jump during the current frame. Which Unity Input method should they use?

Question 2

Why is making the Main Camera a direct child of the Player GameObject in the Hierarchy usually a bad idea for 3D games?

14. Interview Questions

  • Q: Explain the necessity of Time.deltaTime. What specific gameplay bug occurs if a developer uses transform.Translate(Vector3.forward) inside Update() without it?
  • Q: Contrast transform.Translate with Rigidbody.AddForce. In what specific game genre or scenario would you choose one over the other?
  • Q: Why is a camera follow script traditionally placed in the LateUpdate() method rather than the standard Update() method?

15. FAQs

Q: I heard Unity has a "New Input System." Should I use that? A: Unity recently released a massive, complex "New Input System" package for advanced cross-platform development. It is very powerful, but heavily over-engineered for beginners. Start with the classic Input class (as taught here) to learn the logic of game movement first.

16. Summary

In Chapter 6, we brought our game to life. We learned how to read player intent using Input.GetAxis and GetKeyDown. We explored the three distinct methods of movement: Kinematic translation (transform.Translate), Physics forces (Rigidbody.AddForce), and the specialized CharacterController. We protected our game from framerate fluctuations using Time.deltaTime, and we wrote a clean, decoupled LateUpdate script to make our camera follow the action smoothly.

17. Next Chapter Recommendation

Our player can move, but right now they just walk through walls. We need solid boundaries. Proceed to Chapter 7: Physics and Collisions.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·