# Intersection doesn't always works

**URL:** <https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951>\
**Category:** Questions\
**Created:** [January 28, 2021, 12:51pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951 "2021-01-28T12:51:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [January 28, 2021, 12:51pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/1 "2021-01-28T12:51:05Z")

</div>

hey team,

I have below PG where when camera intersect with mesh I am capturing it using `BABYLON.ActionManager.OnIntersectionEnterTrigger`  
[https://playground.babylonjs.com/#NB9U03#1](https://playground.babylonjs.com/#NB9U03#1)

I am using thin instances, so also enabled `thinInstanceEnablePicking`, But the issue is it doesn’t always trigger my event, if you move camera forward in PG, it will output in console.log when camera intersect with mesh but not with thin instances, but when you walk back it will work with thininstance but not with main mesh, I would like to always trigger `OnIntersectionEnterTrigger` whenever I am above those white meshes and thin instances.

what am I missing again?  
Thanks

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 28, 2021, 1:23pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/2 "2021-01-28T13:23:04Z")

</div>

Seems to be working for me. Note that you need to leave the mesh if you want the enter event to trigger again. Your meshes look like this (each mesh has a different color):

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/b0f55172aa10a62e29b12bb3ba2c9a3eff79837b.jpeg)

What exactly doesn’t work?

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [January 28, 2021, 1:51pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/3 "2021-01-28T13:51:29Z")

</div>

@RaananW If you keep moving forward as is in your image, when you are on first 3 meshes (first blue-red-green in your image ), those trigger events when you walk straight, but last 3 doesn’t trigger any event, and when you walk back last 3 are triggering event but not the first 3. please see this video of the issue, I write in console when it doesn’t trigger: [Screen Recording 2021-01-28 at 3.26.53 PM.mov - Google Drive](https://drive.google.com/file/d/1U_GrsrUUtEh8nJ-G8WSvJXiD1DSyK-6j/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 28, 2021, 1:59pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/4 "2021-01-28T13:59:23Z")

</div>

This is because they are considered to be the same mesh. Notice what happens when you enable the bounding box on one of them - it shows both together. The inspector will also not show you any other instance. Thin instances are a wonderful way of achieving a sort of cloning, with some down sides.  
It’s described here - [Thin Instances | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/mesh/copies/thinInstances#how-to-use-thin-instances)

If you want to achieve that, you will have to use instance meshes instead

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [January 28, 2021, 2:12pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/5 "2021-01-28T14:12:12Z")

</div>

@RaananW thanks, but is there something else I can do while using thininstance? Here I simplified an example using just one mesh,  
[https://playground.babylonjs.com/#NB9U03#2](https://playground.babylonjs.com/#NB9U03#2)

you see I am able to capture PickTriggerEvent on click and event does work with thininstance , easily able to capture which thininstance was clicked,

may @Evgeni_Popov have some work around?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 28, 2021, 2:35pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/6 "2021-01-28T14:35:17Z")

</div>

This is because the thin instance picking mechanism is implemented.

But maybe someone else has a better answer, that’s true

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [January 28, 2021, 2:38pm UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/7 "2021-01-28T14:38:44Z")

</div>

Thanks @RaananW , I actually have learned all the thininstance stuff from @Evgeni_Popov and he actually did some PR’s too for some stuff which was not working so thought maybe he know some other trick , I admire your XR stuff, have been reading those… and once I start there I will definitely bug you more xD

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [January 29, 2021, 11:54am UTC](https://forum.babylonjs.com/t/intersection-doesnt-always-works/17951/8 "2021-01-29T11:54:46Z")

</div>

hey @RaananW , as per your suggestion I am trying to create instances in my loop instead thininstance but encountering issue of instance position,

I am creating thininstance and auto adjusting z position in the loop (line 34)` startZ += 20;`  
[https://playground.babylonjs.com/#NB9U03#3](https://playground.babylonjs.com/#NB9U03#3)

Now I need to replace thininstance with instance in above PG, but not able to adjust properly X/Z position, I have to manually adjust X position in the loop with  
`m.position.x = 122;`  
[https://playground.babylonjs.com/#NB9U03#4](https://playground.babylonjs.com/#NB9U03#4)  
if I try to set `m.position.x = obj.position.x;` it doesn’t work

how could I make it work properly without setting x position manually, like I am doing with thininstance PG? in my real project I also have rotationQuaternion which is creating issues.

Thanks

Edit: I even tried to use metrix which looks similar to my thiinstance approach but still position issue [https://playground.babylonjs.com/#NB9U03#10](https://playground.babylonjs.com/#NB9U03#10)

Edit: clone made it work correct position. xD
