I’m using ActionManager.OnIntersectionEnterTrigger to get notified when two balloons collide. However, it seems that Babylon uses a box collider by default. Which causes intersection to trigger when in fact the two balloons didn’t even touch each other (but their “edges” did).
Is there an easy way to use a sphere collider instead, without having to write a lot of code?
I mean, I’m already using CreateSphere() to create my balloons, so Babylon actually knows it’s a sphere - not sure why it attaches a box collider to a sphere… I’ve also tried usePreciseIntersection: true;, but it doesn’t make any difference.
I do not think there is an easy way to change it the only difference between precise or not here is AAB B or OBB (axis aligned vs oriented bounding boxes) I added Cedric to know if there was another mode which I do not think so.
I don’t have a bounding sphere - at least not one that I’ve created myself. I only used CreateSphere(). I don’t know what Babylon does with that under the hood. But from a theoretical perspective, it makes total sense that Babylon thinks the two balloons touched when it uses boxes instead of spheres - see screenshot.
From a Babylon-consumer’s perspective, it’d be nice if Babylon automatically uses spheres instead of boxes to detect intersection (or collisions) when using CreateSphere().
bsphere is used to filter. if bsphere do not intersect, then no need to check with bbox.
Yes, I would try in onBeforeRenderObservable .ActionManager has a feature set. if it doesn’t do what you need, then try to find another solution
How that makes sense, i don’t know same result in babylonjs 4.2.1
Ok the intersect code is a bit confusing setup for performance reasons, i suppose it’s that big to fit the boundingBox corners rather than the actual mesh, since sphere is checked first and ends the function if no intersection is found.
Using your image, spheres look like this.
A custom distance check (since your meshes are always round i assume) would be the best solution for sure
This is because the boundingSphere check is a fast but inaccurate check to see if the meshes are even within range of each other.
it does not decide if the meshes collide, just if the function should continue with a more expensive collision check (boundingBox), this is why the spheres can be next to each other without colliding, but still collide on boundingBox corners.
Here’s an example using a distance check and the spheres actual radii
Remove BABYLON.Engine.CollisionsEpsilon from line #27 if you want collision on touch rather than a slight overlap (BABYLON.Engine.CollisionsEpsilon is 0.001 unit, just be aware of js floating point errors)