Skip to content

Character Movement Algorithms: Pseudocode Reference

A progression of movement systems, each building on the ones before it. Every system is broken into small, named functions rather than one big update() blob — that's how these are actually built and debugged: you want to be able to reason about "did coyote time expire" independently of "did we resolve a collision this frame."

Conventions used throughout

  • dt — delta time in seconds since the last frame. Assume a fixed or clamped timestep; physics constants tuned against a variable, unclamped dt will feel inconsistent on frame hitches.

  • move_toward_vector(current, target, max_delta) — the 2D equivalent, defined in the top-down section.

  • Vector Operations assumed available.
  • input.* functions return raw controller/keyboard state for the current frame.
  • Collision is treated as a black-box resolve_collision(axis) unless the algorithm specifically depends on collision geometry (ledge grab, crouch). A full tile/AABB collision system is out of scope, but the contract is: it adjusts position to the nearest valid spot, zeroes velocity on that axis if blocked, and reports whether a collision occurred.

Move Toward

Acceleration friction movement Jump gravity and coyote time Dash with cooldown and invincibility Wall-slide and wall-jump Variable jump height Jump buffering Air control tuning three models Ledge grab and climb Crouch and crawl with hitbox change Double jump and triple jump Floaty glide parachute toggle Top-down 8-directional movement Twin-stick movement independent of aim Momentum-based vs snappy top-down Grid-based snap movement