Skip to content

Lesson 03 — Turn input into movement ​

Where this lesson fits: the arena has data but the player does not move. This lesson separates device polling from movement rules and makes movement depend on elapsed time.

Time: 2–3 hours

Prerequisites and outcomes ​

Complete lessons 01–02. By the end, you can distinguish held input from a one-frame press and calculate a frame-rate-independent candidate position.

Prepare and run ​

  1. From your learner project's solution folder, follow tutorial chapter 03 steps 1–4.
  2. Open Source\Input\InputManager.cs, InputState.cs, and Source\Systems\MovementSystem.cs. Run the app and follow the tutorial's checkpoint.
  3. Stage note: the staged movement tests arrive in tutorial chapter 04, not chapter 03. Run dotnet test now for existing tests; run the focused movement test after lesson 04.

Code anchors ​

  • last-perimeter/Source/Input/InputManager.cs
  • last-perimeter/Source/Input/InputState.cs
  • last-perimeter/Source/Systems/MovementSystem.cs
  • last-perimeter/Source/Entities/Player.cs
  • last-perimeter/Tests/Systems/MovementSystemTests.cs

Guided operations ​

  1. Inspect InputManager.GetCurrentInput. Identify keyboard, gamepad, deadzone, held movement, and edge-triggered actions.
  2. Trace how the immutable InputState reaches DetermineDirection.
  3. Calculate a candidate with position + direction * speed * deltaTime. Compare two frame durations that add up to the same elapsed time.
  4. Observe direction priority when more than one direction is held; do not silently replace the established rule.
  5. Run the existing tests and move in the game with a keyboard and controller if available:
powershell
dotnet test
dotnet run --project Platforms\DesktopVK

Checkpoint ​

Equivalent elapsed time gives approximately equivalent movement. A held key continues movement, while confirm/cancel/pause are acted on once per press.

Common mistakes ​

  • Applying movement once on key-down instead of every update while held.
  • Multiplying speed by frames rather than elapsed seconds.
  • Treating a menu press like a held movement direction.

Questions and extension ​

How should a stick deadzone affect diagonal or noisy input? Use the existing input state as the contract and add a focused test if the behavior changes.