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?
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