Sign in to follow this  

Question About Proper Handling of Collision w/ Multiple Objects

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this