05 — 2D Platformer Movement
Run Tools → Input System Starter Kit → Create 2D Platformer Demo in an empty scene, press Play, and feel it: run with A/D or the stick, jump with Space — tap for a hop, hold for full height. Then open Scripts/Platformer2D/PlayerController2D.cs and follow along.
The input layer (the part this course is about)
Moveis polled inUpdate:moveAction.ReadValue<Vector2>().x. Horizontal movement is a state ("how far is the stick?"), so polling fits.Jumpuses events:performedstamps a jump-buffer timer,canceledcuts upward velocity for variable jump height. Jumping is a moment, so events fit.
That pairing — poll the values, subscribe to the moments — is the pattern you'll reuse in every genre.
The physics layer (quick notes for completeness)
- Input is read in
Update(every rendered frame, so no missed presses), but velocity is applied inFixedUpdate(physics steps). Passing values from one to the other via fields is the standard bridge. - Grounding uses a thin
Physics2D.BoxCastunder the collider. The demo player sits on the Ignore Raycast layer so the cast can't hit the player itself — a classic gotcha, solved in data rather than code. Rigidbody2Dsettings that matter: Freeze Rotation ✓, Collision Detection Continuous, gravity scale ~3.5 (real gravity feels floaty in platformers).
The game feel layer (why it doesn't feel like a school project)
- Coyote time (0.1 s) — you can jump for a moment after running off a ledge.
- Jump buffering (0.1 s) — pressing jump just before landing still jumps.
- Jump cut — releasing early multiplies upward velocity by 0.5.
Comment each of these out (they're clearly marked) and play again — students immediately understand why every good platformer does this.
Exercises
- Wire the Dash you added in 03 - The Input Actions Asset: find the action in
OnEnable, subscribeperformed, and impulsebody.linearVelocityin the facing direction. Bonus: a cooldown timer. - Change
Move's gamepad binding to add a Processor (select the leftStick binding → Properties → Processors → Stick Deadzone) and raise the deadzone until drift stops on an old controller — no code, that's the point. - Add a
Crouchaction bound to S/left-stick-down that halves the collider height.
Compare with the community approaches in this video platformer series and this written one.