本文へスキップ
Unity Tutorial

Move a 3D player with the keyboard in Unity

Use Input.GetAxisRaw and a CharacterController to build readable WASD movement.

公開日: 2026-06-03#Unity#Input#CharacterController#3D
+
*
+
Coco, the guide character・喜ぶ
Coco
Game dev learning guide
This English lesson uses the same guided screen structure as the Japanese tutorials: a visual start, character guidance, step cards, code, mistakes, and a final checklist.
+
*
+
Hajime, the learner character・混乱
Hajime
Beginner game engine learner
I want to know what to make first, what to check, and how to tell whether I actually understood it.
Coco, the guide character
Move a 3D player with the keyboard in Unity is designed around one visible result. We will keep the first pass focused so the lesson turns into practice quickly.
Hajime, the learner character
So I should finish the exact lesson once before changing it?
Coco, the guide character
Yes. Finish the stable version first, then change one variable, setting, or layout detail to make the idea yours.

Lesson Overview

Finish one working result first

1.

Goal

This lesson introduces a classic beginner movement controller. The focus is not on advanced physics, but on understanding how keyboard input becomes motion in the scene.

2.

Time

25-35 min / Beginner. Keep the first pass small, then change one thing on your own.

3.

Result

WASD or arrow keys move the player.

Before You Start

Check the goal, inputs, and success condition

The lesson is easiest to follow when you know what should happen on screen, which control or editor action triggers it, and what counts as done.

1

This lesson introduces a classic beginner movement controller. The focus is not on advanced physics, but on understanding how keyboard input becomes motion in the scene.

2

Read horizontal and vertical input from Unity's standard input axes.

3

WASD or arrow keys move the player.

1Conclusion first

Keyboard movement is one of the first patterns many learners want to build because it makes a 3D scene feel interactive right away. Unlike a passive demo, movement lets you test your own input, feel the response, and judge whether the controls seem stable or awkward.

This lesson focuses on a readable approach using CharacterController and Input.GetAxisRaw. That combination is practical for beginners because it keeps movement code explicit. You can clearly see where input comes in, how a movement vector is created, and how it becomes actual motion in the scene.

2What you will learn

  • Read horizontal and vertical input from Unity's standard input axes.
  • Turn two input values into a normalized 3D movement direction.
  • Move a player with CharacterController without immediately dealing with full Rigidbody physics.
  • Rotate the player toward the movement direction so the result feels more natural.

3Before you start

  • A player object with a CharacterController component attached.
  • A visible floor or platform so movement direction is easy to judge.
  • Basic knowledge of the difference between local forward and world forward.
  • A camera angle that lets you clearly see whether the player turns and moves correctly.

4Step by step

1
Step 1
Prepare a player object
Create a simple player object and add a CharacterController so you can move without writing a full physics controller first.
2
Step 2
Read horizontal and vertical input
Use Input.GetAxisRaw for Horizontal and Vertical to capture clear WASD or arrow key movement values.
3
Step 3
Convert input into world movement
Build a Vector3 from those values, normalize it when needed, and pass it to CharacterController.Move multiplied by speed and deltaTime.

5Keyboard movement

Keyboard movement
csharp
using UnityEngine;

public class KeyboardMove3D : MonoBehaviour
{
    [SerializeField] private float moveSpeed = 5f;
    [SerializeField] private CharacterController controller;

    private void Update()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float z = Input.GetAxisRaw("Vertical");

        Vector3 move = new Vector3(x, 0f, z).normalized;
        controller.Move(move * moveSpeed * Time.deltaTime);
    }
}
  • Input.GetAxisRaw gives direct values without smoothing, which makes the beginner behavior easier to observe and explain.
  • Normalizing the vector prevents diagonal movement from becoming unintentionally faster than single-axis movement.
  • CharacterController.SimpleMove or Move handles practical movement nicely for this stage before you step into more advanced physics-driven controllers.

6Common mistakes

Diagonal movement feels faster

This is a classic beginner bug. When both axes are pressed, the resulting vector is longer than moving in only one direction. Normalizing the vector fixes that by keeping the total length under control.

The player moves in the wrong direction

If movement seems rotated relative to the model, check the player's forward orientation in the scene. Some imported models are not aligned the same way as Unity's default forward direction.

The player moves but never turns properly

Rotation only makes sense when the move vector is large enough. If you try to rotate toward a tiny or zero vector every frame, the result can feel jittery or undefined.

7Checklist

  • WASD or arrow keys move the player.
  • Diagonal speed is controlled by normalizing the movement vector.
  • Movement logic is readable enough to extend later with jumping or camera-relative input.

8Practice ideas

  • Make the movement camera-relative instead of local-forward relative.
  • Add a sprint key that temporarily increases moveSpeed.
  • Introduce a jump later and compare how CharacterController changes your vertical movement logic.

9FAQ

Why use CharacterController for a first movement lesson?

It keeps the first version easier to reason about. You can focus on input and motion without immediately solving advanced Rigidbody setup, drag, force balancing, or collider behavior.

Should I use GetAxis instead of GetAxisRaw?

GetAxis gives smoothed values and can feel nicer, but GetAxisRaw is easier to explain at the beginning because the input jumps cleanly between simple values.

Can I make the player move relative to the camera?

Yes, and that is a strong next step. Camera-relative movement is common in third-person games, but it adds a second layer of vector reasoning, so it is often better as the follow-up lesson.

Why does this lesson avoid Rigidbody?

Not because Rigidbody is bad, but because it introduces more variables. The simpler path first usually helps learners understand the intent of their controls before adding physics complexity.

10Wrap-up

  • The heart of keyboard movement is simple: read input, build a direction, normalize it, then move with a stable speed.
  • CharacterController is a useful educational stepping stone between static scenes and more advanced player systems.
  • Once this movement is comfortable, adding jump, sprint, camera-relative control, or animation becomes much easier.

11Character review

Hajime, the learner character
If I can make the result once and explain what changed, I can move on with more confidence.
Coco, the guide character
Exactly. The best next step is one small variation: adjust a value, swap an input, or connect the idea to a tiny scene of your own.
Tiny variation: finish the lesson once exactly as written, then change one value, label, axis, or UI detail. That small change is where understanding starts to stick.

Next tutorials