Ray casting + ray helper info

Hello there :sweat_smile: :vulcan_salute:
I was trying to cast 6 different rays from an object in different directions.

Is there any way to visualize the casted rays?
I tried with RayHelper but that doesnt seem to work… I can set the RayHelper to show up correctly, orientated in the right way, but then the ray intersections doesn’t seem to match the values…
PG: https://www.babylonjs-playground.com/#780S0V#9

If I just use RayHelper without specifying direction, should it inherit that property from the Ray wich they are attached to? :zipper_mouth_face: If so, seems like Ray direction is not set correctly. Seems like they all still pointing in the same direction…

PG without direction on RayHelper: https://www.babylonjs-playground.com/#780S0V#11

Update: seems like I dont need to attach the ray to mesh, is this how it suppoed to work?
Becouse the ray intersection method still matches all wrong meshes, even if the display is ok.

Can you help me figure out the correct implementation? :pray: Thanks!

Ok, seems to be working now. How I solved it? By refactoring… :sweat_smile:
Here update PG: https://www.babylonjs-playground.com/#780S0V#17
Duble-click the canvas to randomly set the player/cube position.
If a collision is detected, the corresponding mesh will change color.

1 Like

Oh yeah, the problem was with rayHelper.attachToMesh(player);

1 Like

If the cube is rotated, the rays will still be casted in the same direction. Im working on a way to make the rays rotate with the main mesh. So the front is always the front of the model, even if it rotates.
Here my not working pg: https://www.babylonjs-playground.com/#780S0V#22

1 Like