# Odd Ray behavior

**URL:** <https://forum.babylonjs.com/t/odd-ray-behavior/1985>\
**Category:** Questions\
**Created:** [March 19, 2019, 9:03pm UTC](https://forum.babylonjs.com/t/odd-ray-behavior/1985 "2019-03-19T21:03:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [March 19, 2019, 9:03pm UTC](https://forum.babylonjs.com/t/odd-ray-behavior/1985/1 "2019-03-19T21:03:11Z")

</div>

Hi guys, i feel like i’m missing something here… I can’t quite work it out.

This ray is cast from 0,0,0 to 10,0,0. but it intersects with box\_a at -5,0,0 …  
box\_a is the first mesh created in the scene, but surely it shouldn’t be hit by the ray…?

If i remove box\_a from the scene, the ray intersects with box\_b at 10,0,0 - but i think it should be stopped by the plane at 5,0,0 ?

[https://www.babylonjs-playground.com/#KNE0O#158](https://www.babylonjs-playground.com/#KNE0O#158)

```
Console.logs;
/with box_a
..new ray cast..
origin e {x: 0, y: 0, z: 0}
target e {x: 10, y: 0, z: 0}
direction e {x: 1, y: 0, z: 0}
hit BOX_NOT_IN_RAY_DIRECTION e {x: -5, y: 0, z: 0}

/without box_a, but still with "wall" (plane at 5, 0, 0)
..new ray cast..
origin e {x: 0, y: 0, z: 0}
target e {x: 10, y: 0, z: 0}
direction e {x: 1, y: 0, z: 0}
 hit BOX_IN_RAY_DIRECTION e {x: 10, y: 0, z: 0}
```

---

<div class="post-metadata">

**Author:** ![Devin\_Wright](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/devin_wright/32/4302_2.png) [@Devin\_Wright](https://forum.babylonjs.com/u/Devin_Wright)\
**Post date:** [March 19, 2019, 10:01pm UTC](https://forum.babylonjs.com/t/odd-ray-behavior/1985/2 "2019-03-19T22:01:30Z")

</div>

It seems like maybe the scene needs to be rendered first or something like that?  
[https://www.babylonjs-playground.com/#KNE0O#159](https://www.babylonjs-playground.com/#KNE0O#159)

Here I just set up a simple call and Plane gets returned now.

---

<div class="post-metadata">

**Author:** ![trevordev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trevordev/32/16_2.png) [@trevordev](https://forum.babylonjs.com/u/trevordev)\
**Post date:** [March 19, 2019, 10:03pm UTC](https://forum.babylonjs.com/t/odd-ray-behavior/1985/3 "2019-03-19T22:03:29Z")

</div>

Yep, Internally babylon does not update object matrices from pos/rot/scale of objects automatically until the frame is renderer so you can either do this manually with computeWorldMatrix or render the scene as Devin mentioned.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [March 20, 2019, 2:29am UTC](https://forum.babylonjs.com/t/odd-ray-behavior/1985/4 "2019-03-20T02:29:10Z")

</div>

Ahhh of course… I was scratching my head why it wasn’t working when the doc demo work just fine 😄  
Cheers
