IntersectsMesh not working

Hi everybody,

I’m sure I’ve made a mistake but i don’t understand where because the code is quite simple.

Here’s the PG : https://playground.babylonjs.com/#INZ0Z0#590

I really do not understand why the blue cube intersects the ground.

Thanks in advance for your help.

Boris

Because at the time of intersectsMesh, the newly created mesh has not yet calculated the world matrix.
multimat mergeMesh | Babylon.js Playground (babylonjs.com)

    cube2.computeWorldMatrix(true, camera)
    var table_meshes = intersection(cube2, scene)
    console.log(table_meshes)

or

scene.onAfterRenderObservable.addOnce(() => {
      var table_meshes = intersection(cube2, scene)
      console.log(table_meshes)
  }) 

Wait for the next frame to calculate the world matrix before calculating the intersection, or force the world matrix to be calculated.

3 Likes

Thanks a lot !!!

1 Like

If you encounter weird problems, try scene.onAfterRenderObservable Time to solve most problems. This is my secret to trying my luck to solve the problem. :grin:

2 Likes