# Mesh intersection trigger accuracy

**URL:** <https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397>\
**Category:** Questions\
**Created:** [July 15, 2021, 1:33pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397 "2021-07-15T13:33:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbase](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dbase/32/9431_2.png) [@dbase](https://forum.babylonjs.com/u/dbase)\
**Post date:** [July 15, 2021, 1:33pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/1 "2021-07-15T13:33:43Z")

</div>

Hi folks,

I have created a disc primitive like so:

```auto
const s = new Mesh.CreateDisc(
  `Step_${step[2]}`, step[0], step[1], this._scene, false, true
);

```

I’m attempting to use the action manager of a moving mesh to collide (intersect) with the mesh like so:

```auto
asset.meshes[1].actionManager.registerAction(
  new ExecuteCodeAction(
    {
      trigger: ActionManager.OnIntersectionEnterTrigger,
      parameter: {
        mesh: this._steps[i],
        usePreciseIntersection: true
      }
    },
    () => {
      console.log("IN", this._steps[i].name.split('_')[1]);
    }
  )
);

```

This works well however the moving mesh is triggered by the bounding box and not the mesh itself. I assumed that the usePreciseIntersection would solve this but that’s not the case.

What would be a more correct way of detecting this sort of collision? I don’t want to block collision movement using checkCollision. My interaction is more nuanced and I’m already using that form of detection for boundaries.

Thanks!

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 2:48pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/2 "2021-07-15T14:48:24Z")

</div>

@dbase Can you try usePreciseIntersection: false and let me know ??? I can almost certainly see a bug here but would like confirmation… ☹

---

<div class="post-metadata">

**Author:** ![dbase](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dbase/32/9431_2.png) [@dbase](https://forum.babylonjs.com/u/dbase)\
**Post date:** [July 15, 2021, 3:02pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/3 "2021-07-15T15:02:57Z")

</div>

Nope neither true or false seem to work. I forgot to mention my dependency list btw. Here it is:

```auto
"dependencies": {
  "@babylonjs/core": "^5.0.0-alpha.31",
  "@babylonjs/gui": "^5.0.0-alpha.31",
  "@babylonjs/loaders": "^5.0.0-alpha.31",
  "@babylonjs/materials": "^5.0.0-alpha.31"
},

```

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 3:05pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/4 "2021-07-15T15:05:03Z")

</div>

Could you create a repro in the playground? This would help a lot

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 3:05pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/5 "2021-07-15T15:05:42Z")

</div>

Even if it only contains a disc and another mesh, at least it would speed up our investigation

---

<div class="post-metadata">

**Author:** ![dbase](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dbase/32/9431_2.png) [@dbase](https://forum.babylonjs.com/u/dbase)\
**Post date:** [July 15, 2021, 5:16pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/6 "2021-07-15T17:16:35Z")

</div>

Hey! Thanks for getting back so quick. I’m caught up in my day and started through the process of recreating something similar to my setup. In my case sphere is actually a base gltf mesh. I also had some errors setting it up in playground and ran out of time debugging/completing it. Here’s as far as I got: [https://playground.babylonjs.com/#CPSPZA#4](https://playground.babylonjs.com/#CPSPZA#4)

Sorry for the half-assed nature of it. The idea was that I was going to animate the sphere moving into the bounding box of the disc and have it change its visibility or change the texture colour on the sphere. I’m not sure if this gets you any closer!

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 7:54pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/7 "2021-07-15T19:54:26Z")

</div>

The playground is throwing an exception, would be great if you could isolate the disc and the sphere indeed 🙂

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 15, 2021, 10:51pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/8 "2021-07-15T22:51:42Z")

</div>

Ok I double checked and precision is working correctly, basically precise means that the bounding box is not necessarily Axis Aligned: [Mesh Intersections | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/mesh/interactions/mesh_intersect)

This will still not trigger mesh to mesh intersection which would cost a lot.

This could be of interest [Precise mesh intersection detection - #4 by Raggar](https://forum.babylonjs.com/t/precise-mesh-intersection-detection/8444/4)

---

<div class="post-metadata">

**Author:** ![dbase](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dbase/32/9431_2.png) [@dbase](https://forum.babylonjs.com/u/dbase)\
**Post date:** [July 16, 2021, 1:58pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/9 "2021-07-16T13:58:11Z")

</div>

HI Sabavan, so sorry about that. I was under a great amount of stress to get a delivery out. Sorry I wasn’t more helpful. Here’s a link to our prototype: [Boehringer Stage](https://bit.ly/2VUjqND) once loaded click “customize” and then “follow” you can then move the character around the mainland.

![Screen Shot 2021-07-16 at 9.56.21 AM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/b/9b4e7d5c78bb4237b39d8e422c3a341b347d9c03.png)

If you angle the avatar to the edge of the floating white disc you’ll see it intersects at the edge. I suppose this is what you’re referring to as being axis aligned. I’ll have to investigate a different method.

Here’s a better question though: we were going to use these sort of primitive collisions to determine the avatars y coordinate. This ensures that they are scaling the grand. Both the mainland environment and avatar are both gLTF models.

Is there a better way to introduce ramps/stairs in this case?

We’re not using any scene gravity controls as I wan’t sure how that would play out with gltf models.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 16, 2021, 2:08pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/10 "2021-07-16T14:08:37Z")

</div>

In your case, ray casting down to find the closest ground would be good I guess and for object collision you could have a look at this one: [Camera Collisions | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/cameras/camera_collisions#4-object-vs-object-collision)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 16, 2021, 2:08pm UTC](https://forum.babylonjs.com/t/mesh-intersection-trigger-accuracy/22397/11 "2021-07-16T14:08:53Z")

</div>

and by the way I love the website 🙂
