raise a custom event when a collision occurs

User avatar
squisher
Posts: 11
Joined: Wed Jul 30, 2008 6:08 pm

raise a custom event when a collision occurs

Post by squisher »

Hi,

I'm working on a 3d space game and I want to be able to register a function that will be called every time a missile hits an asteroid or a ship. The function will delete the missile and spawn an explosion at the point the collision occurred. How can I get Bullet to call this function? Is there a better approach?

I tried the custom callback code from the character demo that uses 'setOverlappingPairUserCallback', but it triggers the callback for every broadphase "collision". In other words, it causes the missile to explode when it gets *near* an asteroid, when it should only explode when it actually hits the asteroid.

Any guidance would be greatly appreciated.
ThomasS
Posts: 3
Joined: Thu Jul 31, 2008 11:31 am

Re: raise a custom event when a collision occurs

Post by ThomasS »

If you just want to know if a collision happened (not how strong it was), you can set up a "contact added" callback (link).

By handling the "contact processed" callback it should also be possible to get a measure for the strength of the collision (m_appliedImpulse of the btManifoldPoint passed as parameter), but for me this callback was not called every time, for example not for sphere<->sphere collisions.

Another method is to iterate over all btPersistentManifold like described here. I still have to try this out, so I don't know if it's possible to get the collision strength this way.