Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks, this should work –  user389006 Apr 10 '13 at 13:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.