I’m using a physics engine (cannon) and I would like to generate a sound if 2 objects collide.
There I ran into 2 problems:
I would like get a notification if any collision happens. Either any collision of any object with any other object (PhysicsImposter). Or, any collision with one specific PhysicsImposter.
I have found only OnCollideEvent but that is deprecated. The other collision events seem to require to register certain objects beforehand.
I would like to know with which force/impulse the 2 objects collided. I would like to use this to control the volume of the played sound.
Unfortunately, I didn’t find any way to get the inter penetration depth. I can add that support for ammojs but I didn’t find anything for cannon. I guess something exists.
As a workaround, you can compute the distance between the position of impostor and the contact point. The shorter it is, the bigger the penetration.
@RaananW did you used penetration depth for your latest VR sound demo ?
The way I’m doing it, is by taking the difference in velocity of the last frame and the current frame. I then use this to calculate the impact, when a physics body is colliding with something. It’s not exactly the most accurate way, but it seems to work for me.
Thanks a lot for all the good answers.
I have tried the addEventListener(“collide”, …) with getImpactVelocityAlongNormal().
This works very well for me.