How do I prevent my platformer's character from clipping on wall tiles?

Posted by Jonathan Hobbs on Game Development See other posts from Game Development or by Jonathan Hobbs
Published on 2012-05-21T02:09:31Z Indexed on 2012/06/10 16:48 UTC
Read the original article Hit count: 270

Currently, I have a platformer with tiles for terrain (graphics borrowed from Cave Story). The game is written from scratch using XNA, so I'm not using an existing engine or physics engine.

The tile collisions are described pretty much exactly as described in this answer (with simple SAT for rectangles and circles), and everything works fine.

Except when the player runs into a wall whilst falling/jumping. In that case, they'll catch on a tile and begin thinking they've hit a floor or ceiling that isn't actually there.

The player is moving right and falling downwards. So after movement, collisions are checked - and first, it turns out the player character is colliding with the tile 3rd from the floor, and pushed upwards. Second, he's found to be colliding with the tile beside him, and pushed sideways - the end result being the player character thinks he's on the ground and isn't falling, and 'catches' on the tile for as long as he's running into it.

I could solve this by defining the tiles from top to bottom instead, which makes him fall smoothly, but then the inverse case happens and he'll hit a ceiling that isn't there when jumping upwards against the wall.

How should I approach resolving this, so that the player character can just fall along the wall as it should?

© Game Development or respective owner

Related posts about collision-detection

Related posts about tiles