Page 1 of 1

Simultaneous collision with multiple static shapes

Posted: Thu Dec 02, 2010 6:17 pm
by Dailuaine
Hi,

firstly, thank you! Chipmunk is so much fun to work with. I've just started out on iPhone development and am enjoying working with your physics engine immensely!

Once strange behaviour I have seen is that if I have a row of static boxes, like bricks in a wall, when a circular body bounces off them, it bounces at an unexpected angle (ie not angle-of-incidence = angle-of-reflection :) ). I'm assuming this is because the circular object is hitting the vertices of one or both boxes and the circle-vertex collision is some how overriding the circle-line collision that would occur on the same frame?

I need the static boxes to all exist separately as I'm trying to write a "music generator" that plays sounds, notes, etc when balls hit the different blocks, and it is much easier to treat each block as a distinct object.

I've tried "growing" the collision boxes slightly to get the edges overlapping with the vertices, and I've tried increasing the number of iterations the engine does to improve detection, but neither of those seem to be the solution.

Is there something else I should do?

Thanks in advance to anyone who can help,

D.

Re: Simultaneous collision with multiple static shapes

Posted: Thu Dec 02, 2010 7:14 pm
by slembcke
Unfortunately this is a limitation that can't be easily fixed. Swept collisions might help some, but not entirely solve the problem.

I would combine nearby boxes together to get rid of the "cracks" between them. Then using a collision callback, get the collision points and test those against the original music boxes. You could even use Chipmunk's point queries and layer bitmasks to help you out. Put the balls and the collision geometry on one layer and put the music boxes on a second. Then you can point query the second layer using the collision points. It would save you some effort if you wanted non-triviall sound trigger shapes. Though if everything was just plain axis aligned boxes it would probably be easier to just use a for loop.

Re: Simultaneous collision with multiple static shapes

Posted: Thu Dec 02, 2010 7:49 pm
by Dailuaine
Thanks for the response. I was reaching the conclusion it wasn't possible, but thought there was a chance I was doing something wrong (it happens, occasionally! ;) )

Your alternate approach is exactly what I was considering as a backup plan, so I'll go with that.

Cheers,

D.