Page 1 of 1

Collision Detection

Posted: Thu Feb 02, 2012 12:42 pm
by BmB
I'm aware of both love.physics and Hardoncollider. But I'd like to hand tailor my collision and also learn something.

So far as I understand collision detection ordinarily works by comparing each object/surface to all the other objects in the scene? I can imagine it is optimized by first testing for say a bounding box or part of the level before doing per pixel/polygon/line etc. collision? But I can't help but think there's got to be a better way than this. It seems extraordinarily wasteful. I just can't think of it yet. Any ideas?

Re: Collision Detection

Posted: Thu Feb 02, 2012 1:36 pm
by gfreak

Re: Collision Detection

Posted: Thu Feb 02, 2012 3:07 pm
by ivan
Collision detection can be a very complicated problem.
First, you need to identify the scope of your collision system:
Do you just need to detect if 2 shapes intersect (which is fairly easy) or do you want to have collision response as well (at this point you may need to program an entire physics engine).
Based on this you have to choose if you're going to make a static or a continous collision detection system.
Stacking of objects (where you have a number of objects on top of each other) can be a complicated problem as well - if you plan to have this feature you may need to look into 'collisions solvers'.
Regarding limiting the number of collision tests, this can be done during the 'broadphase' in a number of ways: using spatial partitioning as gfreak said, collision groups/filters and so on.

Re: Collision Detection

Posted: Thu Feb 02, 2012 3:30 pm
by kikito
BmB wrote:So far as I understand collision detection ordinarily works by comparing each object/surface to all the other objects in the scene? I can imagine it is optimized by first testing for say a bounding box or part of the level before doing per pixel/polygon/line etc. collision?
Usually only the bounding boxes are compared. Sometimes you can aproach some images with geometric figures (circles, triangles) which allow for finer-grained calculations. "Pixel-perfect" collision, ignoring transparent pixels in images, is too slow in LÖVE, and no one does it.

As gfreak is saying, spatial hashes allow you to limit the number of bouding box comparisons. You place each shape in a grid, so that every time you have to perform the calculations you only compare it with the shapes on the same grid, and the others are ignored.

Re: Collision Detection

Posted: Thu Feb 02, 2012 4:30 pm
by MarekkPie
And if you don't want to use HardonCollider...

[cough] LoveHash [/cough]