A mesh says its intersecting itself?

I have a loop:

for (var i = 0; i < scene.meshes.length; i++) {
   if (mesh.intersectsMesh(scene.meshes[i], true)) {
      //I do stuff here
   }
}

And with a consle.log it says that the mesh is colliding with itself, even though it’s not? That’s confusing, but I’m pretty sure a thing can’t intersect with itself because it’s kinda obvious that if it could then it would always be intersecting itself.

So how do I filter out the collision with itself? I have 3 meshes: mesh, ground, and wall.

Hey, I don’t have the answer for ‘why is happening this’ but I have the workaround,
add before intersectMesh

if (scene.meshes[i] == mesh) continue;

https://playground.babylonjs.com/#I0CY84#1 lines 85-94

Here my pg. I tried that, but a little different. I have if scene.meshes[i].name != car . Is it any different if iI use scene.meshes[i] or scene.meshes[i].name?

EDIT: NVM it works if I don’t do scene.meshes[i].name. updated: https://playground.babylonjs.com/#I0CY84#2

Greeeat!
As a suggestion, you can add your obstacles in a different array and check all the time the meshes from that array instead from the entire scene, cause you can have 1000 meshes in the scene, but maybe you want to check intersection with only 5 of them. Cheers!:beers:

1 Like

Thanks! Might be useful if I have background meshes!

1 Like