Hi Jsdream. What a wonderfully thorough post you have written! Fantastic!
What if I saidā¦ the ācollidersā for this type of collision systemā¦ is not the mesh shape, nor the boundingbox-extends? What ifā¦ it were an ellipse/sphereā¦ whose (half-)size is stored in anymesh.ellipsoid? That would be a surprise for you, huh?
https://www.babylonjs-playground.com/#KJRQM7#15
And there they are, the green ellipsoid collidersā¦ sized and displayed via two badly-coded-by-wingnut functions in lines 2-52 (called overloads). Those green ellipsoids are temporary āvisualizersā stored in a meshās .ellipsoidMesh propertyā¦ which is a property I just add myself. Tools in the playground āInspectorā may be able to display these collider ellipsoids, too. I havenāt checked real well. I have always used these two junky funcs I made.
I also added freecam mousewheeling in lines 72-103. Someday weāll code a core freeCameraWithWheelControlā¦ for use in camera.inputs.
Lines 146-148 is where I call the two āellipsoid viewer helper funcsāā¦ on each blockMesh. Line 147 - blockMesh.setEllipsoidPerBoundingBox(scene); might not be needed. BJS often sets .ellipsoid size == mesh boundingbox-extendsā¦ automatically (as best it can).
(Thereās also anymesh.ellipsoidOffset = anyvector3ā¦ for offset-positioning the ellipsoid collider on any mesh, if ever needed. It is sometimes used to raise/lower cam-viewā¦ for gravity-active ground-skidding freecams.)
Andā¦ one other important thingā¦ which you may not ever need. engine.collisionsEpsillon ā¦ a float value that determines what collide-angle is a ādead-stopā and what collide-angle is a āglance-offā.
But the main thing hereā¦ is showing you the shape of genuine colliders (for this type of non-physics-engine colliding). I think you now understand WHY some of your āedgeā shots are missing the intended targets, and instead, colliding with the wrong targets. Itās all about the collider shapes, eh? The more above-the-board that the shot is fired-from, the less chance of missed collisions.
There IS bounding-box type of colliding (intersecting) available, though.
Look at THIS classic playground - carefully: https://playground.babylonjs.com/#KQV9SA#0 IntersectsMesh (precise or loose) and intersectsPoint. Pretty good collision detect. Perhaps precise would work perfectly for you.
The colliding system you are trying to useā¦ was originally designed for simple FPS gamesā¦ freeCameras colliding with mesh obstacles. MoveWithCollisions is a little bit of a cheater. It allows mesh to collide with other mesh (ellipsoids-only, not boundingBoxes/intersectsMesh). But, like all cool tools in BJS, try anything with everythingā¦ its part of the fun.
If you DO change to an intersectsMesh systemā¦ you will no longer have .moveWithCollisions() availableā¦ at least i donāt think so. All .checkCollisions = true/false will no long be used, either.
Intersecting is not the same as collidingā¦ butā¦ intersecting works fine for SOME stuff, as you can see by that last playground. It might work for you. Iād sayā¦ stay with āpreciseā. Butā¦ even thenā¦ the shape, and the close-proximity of your meshesā¦ might cause trouble for intersectsMesh().
There is one other possibility. For all your hexagonsā¦ add a ātop capā to each oneā¦ a real THIN hexagon atop the thicker ones. Then put a .checkCollisions on THAT. (a few more meshes, but what the heck?) That top-cap collider will be REALLY flat and near-full-coverage circularā¦ and it MIGHT prevent the missed edge collisions. Remember that you are allowed to fully adjust the vector3 value of mesh.ellipsoidā¦ like mesh.ellipsoid.multiplyInPlace(new BABYLON.Vector3(1.1, 1.0, 1.1)); (expand the x and z size of mesh.ellipsoidā¦ 10 percent diameter.) ANY adjustment to mesh.ellipsoid size is allowed, and donāt forget the .ellipsoidOffset to raise/lower the colliderās height. Possibilities.
As a possible alternative to top-capping, I wonder what would happen if you raised all the blockMesh collidersā¦ (mesh.ellipsoidOffset.y += somefloat)ā¦ 1/2 height of each blockMesh. hmm. They might protrude too much, and disallow near-edge shots on far-away tiles. But thenā¦ set mesh.ellipsoid.y = .1 (real flat). hmm. Essentially, move the collider up to the top of the tile, and then smash it flat-as-a-pancake. Thatās something to try. Probably, no colliding will happen when shooting-at the SIDES of tiles after that (thru a hole left by a removed tile). (likely a good thing)
If you want green mesh.ellipsoidMesh to dispose when tiles dispose, add mesh.ellipsoidMesh.dispose();
just before line 169.
Ok, thatās all I know. Stay tuned for more ideas/options. I hope I have been helpful. Perhaps we could/should move this thread/topicā¦ to the Questions & Answers sub-forum? shrug