Jump to content
  • Advertisement
Sign in to follow this  
ManicPumpkin

Collision detection of many objects (calculation problem)

This topic is 1672 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

Hello,

 

currently I think about a problem of one of my projects. The problem is, I generate a world with some objects and a player object, that's able to walk inside this world. The first question I've is how I can detect collisions in a simple way?

 

All of my objects have a bounding box. So I'm able to detect intersections with every game tick between two or more objects. I guess, this is the simplest of all ways, but my problem is now, if I have a world with more than hundred objects? Here a small description ...

 

My idea is, to divide the objects into static and dynamic objects. That means, static objects don't move, like a rock or tree. Dynamic objects are able to move, like a cow or a human NPC's. 

For this moment we only handle static objects and we leave dynamic objects out. I've a rendered view (sight distance of the player) of 12 blocks (means bounding boxes; objects) in one direction. I would render all blocks in any angle around of the player position. Means 12 blocks before, behind, over and under the player. In two dimensions (x and z axis) this are 24 blocks from left to right and 576 blocks on one dimension. I guess, this isn't that much, but if I add the y axis, then I've to render 13.874 blocks. I guess, for collision detection with bounding boxes that would be hard. And to be honest: A view distance of 12 blocks are not really much. So it would be better to increase the distance to 30 or 50 blocks in one direction. But that increases also the calculation problem!

 

The question is, how can I detect collision, with static objects in the world in a good way with many objects? For me, an iteration through all objects to calculate the euclidean distance (which object is the nearest and with which of this objects is a collision possible) seems really hard in cost of calculation?

Is there a good way to calculate this collisions?

 

That is more the simple way to calculate a collision between many static objects and one movable player object, but what if there are some more dynamic objects in the same area like my player object?

 

I would be glad to get some information/resources how to manage this problem in a good way. (-:

Thank you so much!

Share this post


Link to post
Share on other sites
Advertisement

Is your world made of blocks/tiles?  It sounds like it might be, if so you could drastically simplify the collision checks by having a map of what object is in what tile. 

 

If it's not, you might want to look into spatial hierarchies, or doing simpler things, like splitting up things into collision 'layers'.  Sort of like your dynamic/static, but perhaps bullets can't collide with one another, so put them on a distinct layer.  

Share this post


Link to post
Share on other sites

Have you considered using a physics library such as Bullet? Collision detection / response isn't a simple subject and using an existing solution might save you lots of efforts.

 

Cheers!

Share this post


Link to post
Share on other sites

Is your world made of blocks/tiles?  It sounds like it might be, if so you could drastically simplify the collision checks by having a map of what object is in what tile. 

 

If it's not, you might want to look into spatial hierarchies, or doing simpler things, like splitting up things into collision 'layers'.  Sort of like your dynamic/static, but perhaps bullets can't collide with one another, so put them on a distinct layer.  

 

I talked about the bounding box of objects. This bounding boxes are blocks. (-;

But at first, yes, this things are blocks. Later there will be much more complex objects, but I guess, bounding boxes are fine for that, what I plan to program. (;

 

What do you exactly mean with this map? You mean, I've to save all my objects with there coordinates in one hash/array?

Do you have any resources for your ideas?

 

@kauna:

 

I've thought about this, but I want to learn how to solve such problems. In the end, I can use libraries for physics and stuff, but I want to know how is it possible to program that by my own. (-:

Share this post


Link to post
Share on other sites

The spatial hash method is a good one to look into for your particular problem.  Basically, what this means is, you divide your worlds into an X by Y grid of cells, and you only check for collisions between objects within the same cell.

 

Here's a link  to an article discussing it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!