Explosion Collision Detection

How would I detect if something is hit by an explosion? If I shoot my gun using raycast, then how would I detect what I hit around the raycast’s hit point?
Is creating a bunch of bounding spheres and placing them on top of every character in the game as well as on the hit point and checking if they intersect the only way?
Unity has a sweet function ‘Physics.OverlapSphere’ which returns all colliders inside of it.

There is no built-in convenience method in Playcanvas for this, but you can acheive the same result by using Ammo.js directly and using btPairCachingGhostObject with any convex shape, like sphere.

Perhaps I could make an extension… :thinking:

1 Like

If your list of objects surrounding the explosion isn’t that big, you could also check the distance from the explosion in 3-4 different scales as the explosion progresses.

If an object is found to be in an equal or smaller distance each time, then it was hit.

If your objects aren’t small and it’s important to check if part of it was hit, you could create similarly pc.BoundingSpheres and use the interesectsBoundingSphere() method:


I know each way requires some work and it isn’t ideal, but I hope eventually you can get this to work.

I got the result I was after by doing the method I pondered: placing a bunch of bounding spheres on all players and the explosion point and using intersectsBoundingSphere.
But I wanna know how to do the btPairCachingGhostObject, how would I do this? How do I ‘use Ammo.js directly’?
I have a physics doc for bullet which apparently works for ammo.js too, but how do I use functions in it in PlayCanvas? I guess what I am asking is how do I translate the docs into workable code in PlayCanvas.

You can study my project for Convex Cast collision detection, where you can see how I use Ammo.js directly. You are interested in convex-cast.js.

Oh, and not all functions/objects from Bullet are exposed in Ammo. You should check the IDL bindings if it includes the method you are after:

1 Like