I am using height map to generate a terrain, I am using thininstance to populate the area with trees, the issue is I would like to keep my trees above the ground, I used getHeightAtCoordinates, but if height of ground is higher, tree is hidden or floating above…how could I make the tree move above ground?
I changed your camera setting and heightmap to make it easier to view the position of trees. You can change back.
The main problem are the lines I commented out.
// tree.position.x = -27;
// tree.position.z = -50;
// tree.position.y = -0.8;
let totalTress = 700;
var bufferMatrices = new Float32Array(16 * totalTress);
var matrix1 = BABYLON.Matrix.IdentityReadOnly;
matrix1.copyToArray(bufferMatrices, 0);
// tree.position.y = groundOut.getHeightAtCoordinates(0, 0); // Getting height from ground object
These lines making the default position of trees not at origin (0,0,0). You then apply transformation matrix to the tree positions not starting from the origin. Therefore, all your trees have correct relative positions. But not relative to the origin.