Collision detection for multiple objects/types of objects
#1 Members - Reputation: 137
Posted 04 November 2012 - 11:36 PM
Then the last game I did still had 1 type of object that I stored in a vector and of course walls. So for collision detection I just cycled through the vector checking for collisions between the objects.
For more complex games I'm confused though.
For example a game with multiple objects and many types of objects. Not just walls and 1 object.
Maybe a character, bullets he shoots, enemies, etc. All these types of objects have to check collision between each other and handle the actions differently.
So my question is, can someone explain to me or suggest some articles on collision like this? Do I just always check every single object for a collision whether is near, far, relevant or not? Any help would be greatly appreciated! My goal is to get to the point where I can have the knowledge to be able to try making a sidescrolling shooter game, similar to MegaMan or Metroid, etc. Thank you!
#2 Members - Reputation: 817
Posted 05 November 2012 - 12:11 AM
Ive pretty much completed a tetris clone game and I did the collision just fine using a matrix and just checking if the areas are filled or not.
Then the last game I did still had 1 type of object that I stored in a vector and of course walls. So for collision detection I just cycled through the vector checking for collisions between the objects.
For more complex games I'm confused though.
For example a game with multiple objects and many types of objects. Not just walls and 1 object.
Maybe a character, bullets he shoots, enemies, etc. All these types of objects have to check collision between each other and handle the actions differently.
So my question is, can someone explain to me or suggest some articles on collision like this? Do I just always check every single object for a collision whether is near, far, relevant or not? Any help would be greatly appreciated! My goal is to get to the point where I can have the knowledge to be able to try making a sidescrolling shooter game, similar to MegaMan or Metroid, etc. Thank you!
Nice article here
They even have some interactive examples there for you to play with
Edited by ultramailman, 05 November 2012 - 12:12 AM.
#4 Members - Reputation: 1549
Posted 05 November 2012 - 04:37 PM
However, I would also suggest to look at using a 2d physics library. These typically handle all movement and responses of physical objects. You are responsible for assigning it attributes (mass, size, shape, force, velocity, etc.) and it handles the movement and the collision detection. You can allow the engine to handle collisions (ie, have them bounce off each other if elastic), or you can register for a callback when a collision occurs, and do what your game needs to do.
IMO, it take much of the work and does it for you, and I won't make a game without it now. My favorite is chipmunk-physics, but other use Box2d as well.
Good Luck!
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)






