In this series of posts, I describe techniques for implementing AI, pathfinding, and character movement in 2D platformers. I start out by covering some general mechanics of platformers. Then I describe a series of powerful abstraction layers built on top of these basics.
I make references to the Surfacer framework for real-world examples of these techniques. Surfacer is a procedural pathfinding 2D-platformer framework for Godot. It makes it easy to create point-and-click platformer games and to define high-level NPC behaviors.
Although Surfacer is written for Godot, the techniques we discuss in this series are not specific to Godot, and will work in any game engine of your choice!
- How an animation frame loop and physics engine work.
- General platformer mechanics.
- Surfacer's extensible action-handler system.
- How AI movement usually works.
- How to represent a platformer level as a graph.
- How to parse Godot tile-maps into their constituent surfaces—floors, walls, ceilings.
- Some trade-offs of this approach.
- How to decide on "good" jump and land positions for a pair of surfaces.
- How to handle start velocity.
- Separating the vertical component of motion from the horizontal component.
- Detecting collisions with intermediate surfaces.
- Calculating "waypoints" to move around intermediate surfaces.
- Backtracking to consider a higher max jump height.
Part 4: The platform graph and navigation - (COMING SOON!)
- How to construct a platform graph.
- Nodes as positions along surfaces.
- Edges as movement from one position to another.
- Handling platform immutability.
- Navigating through the platform graph to an arbitrary position.
- Optimizing edge trajectories at run-time for a more organic composite trajectory.
- Executing playback of edge instructions.
- Correcting for runtime vs build-time trajectory discrepancies.
Part 5: Character behaviors - (COMING SOON!)
- Examples of common platformer behaviors.
- Transitioning between active behaviors.
- Adding extra bounce.
- Timing behaviors.