# Collision detection for multiple objects/types of objects

This topic is 1903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites

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

##### Share on other sites
Also, you might want to read real-time collision detection book written by Christer Ericson. There could be found some heads up.

##### Share on other sites
It's great to understand how collision detection works in games. You can look up "Spatial Hashing" for more information, on how to efficiently handle collisions.

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!