Difference between revisions of "User:Tepples/Platform game structure"
(Came up with this in the gbdev Discord server. Saving to save work on unreliable bus Internet)
Revision as of 15:27, 3 July 2021
Some notes on what goes into programming a platform game (platformer) for any system:
Platformer physics in a nutshell
- Every object has a position, velocity, and facing direction
- Every frame, add an amount to the vertical velocity, and add the velocity to the position
- Push the object out of terrain
- If the object was pushed out of the floor, give it an option to jump and add to the horizontal velocity
- Move the camera horizontally toward 1/8 of a screen distance in front of the player
- Place the camera vertically to center where the player was last time it was pushed out of the floor, or move it downward if descending and there is a possibility of landing below the visible area. Controlled flight instead uses the previous rule.
Once you have the basics down, there are all sorts of fine-tuning knobs for player character control in platformers, such as these:
- If A has been released and player is still rising, apply gravity at 4 times strength
- Different amounts of horizontal acceleration depending if on ground (stopping and starting) or in air (bending a jump)
- Some games don't move the camera while the player moves back and forth in a small space until the player moves farther away
- Some games let other objects attract the camera while on screen
Some more jump fine-tunes:
- Make the bounding box for pushing an actor out of the floor slightly wider than you might expect. This adds a bit of forgiveness that some people call "coyote time" in reference to Warner Bros.' Looney Tunes animated shorts.
- Jump buffering: treat an A press within 8 frames before landing as a jump. This helps when jumping from stairs, especially in engines that treat slopes as stairs.
- Wall jump: Some characters can jump if A is pressed within 8 frames before or after being pushed out of a wall.
- Mantling: Some characters detect not only the feet but also the top front corner landing on something, in order to grab a ledge for a boost.