Unity Foundations·From empty scene to playable build

Input and player control

Read player input and move a Rigidbody in the right update loop.

Beginner 14 min read Lesson 3 of 300 Challenge included
What you will be able to do
  • Read horizontal and vertical axes each frame.
  • Move a Rigidbody in FixedUpdate, not Update.
  • Normalise the direction so diagonal movement is not faster.

In plain English

The Input System is Unity's newer input package, while the legacy Input Manager is the older built-in approach that still works through methods like GetAxis. Reading axes returns a value from -1 to 1, such as left and right on the horizontal axis. Update runs every rendered frame and is the place to read input, while FixedUpdate runs at a steady physics step and is the place to apply forces to a Rigidbody. A Rigidbody is the component that lets physics move an object, so change its position with physics methods rather than the Transform.

Step by step

  1. 1Create a GameObject with a Rigidbody and a collider.
  2. 2Add a PlayerController component to the same object.
  3. 3Read the horizontal and vertical axes.
  4. 4Build a direction vector and normalise it.
  5. 5Move the Rigidbody with MovePosition in FixedUpdate.
PlayerController.csC#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    [SerializeField] private float speed = 6f;
    private Rigidbody body;

    private void Awake()
    {
        body = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
        body.MovePosition(body.position + direction * speed * Time.fixedDeltaTime);
    }
}

Common mistakes

  • Reading input inside FixedUpdate misses rapid presses, because physics runs at a fixed step rather than every frame.
  • Moving a Rigidbody by setting its Transform position bypasses physics and can cause tunnelling or jitter.
  • Forgetting to add a Rigidbody means GetComponent returns null and the script throws at runtime.
  • Skipping the normalise step makes diagonal movement faster than straight movement.
Your turn

Move a player

Medium

Fill in FixedUpdate to read input and move the Rigidbody with MovePosition.

CSHARP · starter
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    [SerializeField] private float speed = 6f;
    private Rigidbody body;

    private void Awake()
    {
        body = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
    }
}
Check your understanding before moving on.
Knowledge checkQuestion 1

Which method should apply movement to a Rigidbody?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Animation and timelines
Lesson 3 of 300 · 0% of course