Tuesday, November 15, 2011

Wall Kicking

Here is how wall-kicking works:

Desired Outcome
When the player touches a wall, the player should continuously stick to the wall until:
  1. The player touches the ground
  2. The player jumps off the wall
  3. The player presses the DOWN key

The "First Frame" Problem
Most Platformer games collide the player against the environment every frame. When the player overlaps a piece of the ground, wall, or ceiling, the player is moved to the closest point that is not touching the environment. This means that we can only tell if the player touched the environment during the first frame that they touch it. Detecting continuous collision over multiple frames is a little trickier. 

It's pretty easy to tell if the player is constantly touching the ground, since we can count on gravity to keep the player falling through the floor every frame. On walls, we only know that the player has collided on the first touch (unless of course, something is constantly pushing the player into the wall. This is a bad idea unless your character is intentionally sticky, like Meat Boy).