# Question About Proper Handling of Collision w/ Multiple Objects

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

## Recommended Posts

Sorry for the strange title, but I have a general question.

I have a collision detection function that determines if there was a collision between object a and object b. Say I have a player object and like 30 block objects on the screen. Somehow I don't feel the best method for dealing with this is checking to see if there is a collision with the player and all/any 30 blocks, but how else could I do it?

##### Share on other sites
It depends on your game. Is it 2D or 3D?
If it's 2D is it tile or vector based?

If it's tile-based, then you only need to test against the tiles that the player is touching.

If it's vector-based 2D or 3D, you pretty much have to check against all objects, but there is different ways you can check. You can start with faster, more generalized checks and work your way up to slower, more precise checks as you filter out objects by using different collision tests.

##### Share on other sites
To amplify what Gaticus already describes:

A common approach is to use a collision tree of some sort - quadtree in 2D or octtree in 3D. The essence of either approach is to test an object's location or bounding box against a relatively small number of bounding boxes for a quick cull.

Each of the bounding boxes tested against has an associated array (vector, list, etc.) of objects to then be tested against. Those objects may themselves be more bounding boxes or geomety objects.

AABB (axis-aligned bounding box) tests are very quick, comprised of just a few comparisons for each test.

When a bounding box of interest is found, progress on to a more detailed (i.e., more computationally expensive) collision detection (sphere-sphere, point-box, etc.)

However, if your 30 objects are just "blocks," you should probably avoid optimization until you have a performance problem. The general rule is: don't optimize until you have a performance issue that can be solved by optimizing.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013306
×