Search code examples
cocoa-touchcocos2d-iphonechipmunk

How can I detect a permanent collision with the Chipmunk Physics engine


I'm trying to play a "boing" sound when a ball shape hit's any other kind of shape. Which works. But works a little too well....

When the ball comes to rest, or starts to roll, it's in a permanent collision with whatever it's touching, so the "boing" sound fires constantly.

I can't find anything in the chipmunk documentation to tell me when two things are permanently colliding. So I'm thinking I will have to somehow figure it out myself, probably with some sort of timer that compare the last collision against the current collision. But that sounds hacky to me.

Has anyone tackled this issue? How did you solve it?


Solution

  • Couldn't you just play your "boing" sound when contact is BROKEN? There is a callback for that in chipmunk, typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, struct cpSpace *space, void *data)

    That way you get boings whenever it bounces, but not when it's just rolling along. 'course, you'll also get one when it rolls off of your shape, but that could be a feature depending on how you look at it.