1
\$\begingroup\$

I'm building a collision system for my 2D game, broadphasing (sweep and prone + pair detection) works. But I don't know how to separate pickup objects, tiles and the player from each other. My question is; what is the best method for game object type detection? The only thing i come up with is: if(pair.a.type == player && pair.b.type == item) but its does not work if a and b are swapped.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

What I would do is have a list of all of the entities. I would then iterate through all of them checking for collisions. Should I find a collision, I would then call some function on the entity/entities involved, didCollideWithEntity(Entity entity). This is a virtual function which would be overridden in each subclass of Entity, and so each object could then have it's own collision response - this avoids the need for messy if statements.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .