Collision Detection

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
BmB
Prole
Posts: 8
Joined: Mon Jan 30, 2012 8:33 am

Collision Detection

Post 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?
gfreak
Prole
Posts: 29
Joined: Wed Jan 04, 2012 5:32 pm

Re: Collision Detection

Post by gfreak »

User avatar
ivan
Party member
Posts: 1912
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collision Detection

Post 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.
Last edited by ivan on Thu Feb 02, 2012 7:47 pm, edited 1 time in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Collision Detection

Post 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.
When I write def I mean function.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Collision Detection

Post by MarekkPie »

And if you don't want to use HardonCollider...

[cough] LoveHash [/cough]
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest