# IntersectsMesh not working

**URL:** <https://forum.babylonjs.com/t/intersectsmesh-not-working/44875>\
**Category:** Questions\
**Created:** [October 13, 2023, 8:32am UTC](https://forum.babylonjs.com/t/intersectsmesh-not-working/44875 "2023-10-13T08:32:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [October 13, 2023, 8:32am UTC](https://forum.babylonjs.com/t/intersectsmesh-not-working/44875/1 "2023-10-13T08:32:19Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [October 13, 2023, 9:41am UTC](https://forum.babylonjs.com/t/intersectsmesh-not-working/44875/2 "2023-10-13T09:41:08Z")

</div>

Because at the time of intersectsMesh, the newly created mesh has not yet calculated the world matrix.  
[multimat mergeMesh | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#INZ0Z0#594)

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

```

or

```auto
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.

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [October 13, 2023, 9:43am UTC](https://forum.babylonjs.com/t/intersectsmesh-not-working/44875/3 "2023-10-13T09:43:55Z")

</div>

Thanks a lot !!!

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [October 13, 2023, 9:53am UTC](https://forum.babylonjs.com/t/intersectsmesh-not-working/44875/4 "2023-10-13T09:53:27Z")

</div>

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. 😁
