Collision detection of many objects (calculation problem)

Started by
3 comments, last by BeerNutts 9 years, 12 months ago

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!

Best regards,

MANiC.

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.

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!

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. (-:

Best regards,

MANiC.

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.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement