ground.getHeightAtCoordinates(x,z) is hit or miss

[Sticking Objects to the ground | Babylon.js Playground (babylonjs.com)]https://playground.babylonjs.com/#95PXRY#324

I’m having an issue getting object to render directly on top of the heightmap ground.

You can see most of the time (both in the pic, and in the playground), that the trees ‘mostly’ get landed on the groud. But sometimes it’s way off. Is there any way to ensure that all of the trees are on the ground?

As I’m playing with this, perhaps I’m finding that the offset that I’m using getHeightAtCoordinates(x,z)+b could be the problem. The problem may be just knowing where the center of the object is.

Yes. For a sprite as in your PG, it’s sprite.height / 2:

For 3D meshes, you could find it by taking the bounding sphere center and subtracting the bounding box extents in the Y dimension divided by 2.

1 Like