Issue placing the ground just under the mesh, using boundingBoxInfo

Hi everyone,

Hope everyone have a great Thursday!

I am trying to position a ground under a mesh using the getBoundingBox info. But no matter what value I use for the position the ground never move and I dont understand why.

When my mesh is not scaled I have no issue but with a scale of 1000 the position never change.

PG:https://playground.babylonjs.com/#4F33I3#420

Your boundingBoxY calculation is half the difference between the maximum and minimum world coords of the sphere, which results to its center position. So no matter how you scale it, the ground will remain the the center of the sphere, because by default Babylon scales from the center.

In this case why with the same playground with the scaling code commented the ground is positioned where I want.
PG: https://playground.babylonjs.com/#4F33I3#421

in other words, is there a way to always position the mesh at the extremity of the bounding box no matter what the scale is?

It’s because without scaling, (1 - -1) / 2 = 1 which happens to be at the top of the sphere.

Depends on what side of the bounding box you want, here is example.

1 Like

It’s because without scaling, (1 - -1) / 2 = 1 which happens to be at the top of the sphere. → Haaa now I see it make a lot of sense!

I think this piece of code → sphere.computeWorldMatrix(true)
Is really what I was missing in my project.
Thank you very much!

I know, it’s a little gem lost/never written in the doc, discovered this myself the hard way.

1 Like