1

I'm using Chipmunk cocos2d for what will ultimately be a sound-generation game where colliding particles make noise. But right now, I'm running into a problem: my particles keep falling through the floor!

In the example "bouncing ball" templates, the multiplier on the incoming accelerometer stream is fairly low (around 100.0f) but to get things to really react quickly I am cranking it up:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)accel
{   space->gravity = cpvmult(cpv(accel.x, accel.y), 10000.0f); // originally 100.0f
}

I have found that this can be ameliorated by making dt really small, polling the accelerometer around 1/240 of a second.

Is this the best way? Is there another way to say to Chipmunk "look out, these things move fast"?

buildsucceeded
  • 4,203
  • 4
  • 34
  • 72
  • Box2d has the ability to mark a dynamic body as being a 'bullet' (http://www.box2d.org/manual.html#_Toc258082973) , which triggers some additional checks see if it hit another dynamic body along its path. I'm less familiar with Chipmunk but maybe there is a similar concept buried deep within it somewhere? – Paul Dixon Feb 14 '11 at 15:11
  • Yeah, maybe Box2d is going to be the answer here. – buildsucceeded May 17 '11 at 08:59

1 Answers1

3

In general many physics engines have difficulty with collisions between quickly moving objects that are small relative to their velocities. I do not know the specifics of Chipmunk, but your issue implies that at certain time intervals a check is performed for intersecting objects. If the objects move quickly and are small, it is possible for the time interval where a collision is happening to be skipped.

The two easiest solutions are to use a smaller time interval, or somehow make one of the two objects larger. How are you representing the floor? If you can represent it as a thick rectangle, that should also reduce the problem.

The harder solution is to use a more complicated intersection algorithim, such as using bounding capsules to represent the area of space traversed by a sphere between two samples. If the API does not already support this, it is a pretty hefty amount of math and modification.

Chris Pitman
  • 12,990
  • 3
  • 41
  • 56
  • Thanks for this, it's what I suspected. Higher frame rate + gigantic bounding objects = better results. – buildsucceeded Feb 14 '11 at 11:04
  • Although, following back up on this, I can still get things to fall through the floor no matter how big the bounding object is. Whoops, there go my bouncing balls... falling forever. Oh. – buildsucceeded May 17 '11 at 08:59