gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Collision detection

#73797 - ProblemBaby - Tue Feb 28, 2006 3:31 am

Hi

Iam planning to do a platform-game and I need an idea of what kind of info my tiles really needs to do collision detection.

I want to be able to:
Define the whole (or parts) of the tile as unwalkable.
Have slopes.

Whats the best method? Lines, Rects with special Slope flags? I want it to be fast to check for collision, do you have any ideas or experience please tell me.

#73804 - tepples - Tue Feb 28, 2006 4:25 am

Try a height map for each metatile. Sonic 2 for Sega Genesis does something similar.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#73867 - ProblemBaby - Tue Feb 28, 2006 5:34 pm

But how to they do in super mario world for example...
They have one kind of detection that results in collision only downwards (most of the platforms), They have collision from all directions (ie stone blocks) and different kind slopes. What kind of info do you think each metatile contains?

#73890 - sajiimori - Tue Feb 28, 2006 7:58 pm

You could enumerate all the possibilities and switch on it in the engine.
Code:
// First try
enum Type
{
  TYPE_A_DOWNWARD,
  TYPE_A_SOLID,
  TYPE_B_DOWNWARD,
  TYPE_B_SOLID,
  TYPE_C_DOWNWARD,
  TYPE_C_SOLID,
  TYPE_D_DOWNWARD,
  TYPE_D_SOLID,
};

If some parts of the list are repetitive (like repeating every type for downward-only and solid collision), separate those parts into their own bits.
Code:
// Second try
enum Type
{
  TYPE_A,
  TYPE_B,
  TYPE_C,
  TYPE_D,
};

struct
{
  int downwardOnly : 1;
  int type : 2;
};

Split off bits like that as necessary.