I’m sure this issue can be easily solved by experienced programmers, but I’m having trouble figuring it out Is there a simple method for keeping these meshes from overlapping when they spawn at random locations on the ground?

You probably just want to add each new mesh to an array and then brute force check the proposed position of each new mesh against each previously added mesh’s position to make sure they don’t overlap with some poor-man’s collision.

I’ve been using

function distanceVector( v1, v2 ) {
var dx = v1.x - v2.x;
var dy = v1.y - v2.y;
var dz = v1.z - v2.z;
return Math.sqrt( dx * dx + dy * dy + dz * dz );
}

If (BABYLON.Vector3.Distance(mesh[i].position, new Vec3(proposedX,y,proposedZ)) < shoulderWidth) try again.

Something like that.

Alternatively maybe you could just increment initially from 0 with a random x/z value.

for (var ix=0; ix<maxX; ix += Math.rand(spacing)+shoulderWidth){
for (var iz=0; iz<maxZ; iz += Math.rand(spacing)+breastDepth){
new Mesh @ (ix, y, iz) }}

An alternative, you set up a grid with a positioning rectangle within a spacing rectangle order the grid coordinates randomly in a array and choose grid references fr Let om the array in order fro 0 upwards. This way you can never place overlapping objects.

Let positioning rectangle have width W and depth D, let the width and depth of the object to place be w and d respectively. Let X be the width and Z the depth of the spacing rectangle. Min for X is W + w and min for Z is D + d. The smaller the positioning rectangle the more in lines will be the objects and the smaller the spacing rectangle the closer the objects will be.

Hello @JohnK !
What if we don’t know the exact dimensions of the mesh added ; how can we make the ground as different zones(like square zones) and check if there is a mesh already at this zone(considering that a mesh can’t be added to a zone if this one contain another mesh(in its middle ; or at its borders)