A bug with PickwithRay?

Hello everybody,

I don’t understand why i can’t find the distance between two boxes in this example :

I think it’s quite simple but i cannot find my mistake if i’ve made one.

Thanks in advance,


That’s because the world matrices of the meshes are not computed yet when you do the picking. Call computeWorldMatrix() to be sure they are up to date:


Thanks for your answer.

I really don’t understand when and where I must use this function computeWorldMatrix() before doing something else.

Wouldn’t it be easier to call this function each time you create a new mesh in the BABYLON.MeshBuilder function ?

This method is called for you as part of the rendering, so you generally don’t need to call it directly. But in the PG, you are using the picking mechanism in the scene creation method, and at that time the world matrices have not been updated yet.

I think the method is called by the MeshBuilder, but you are updating the position of the mesh, so it needs to be called again after this change for the matrix to be up to date.

1 Like