Odd Ray behavior

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

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}

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

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

2 Likes

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.

2 Likes

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