Making a raycast pass through everything except one physics layer

Godot Version

Question

I have a raycast. I basically want it to pass through all objects in physics layer 1 and save them in an array. Then, when the raycast hits an object in physics layer 2, it should stop the ray. Any help would be greatly appreciated, thanks!

If you are using a RayCast3D node then you’ll need to move the node and use RayCast3D.force_raycast_update() as many times as needed once the first intersection happens. Same for 2D.

The same should be done if you are querying the PhysicsDirectSpaceState3D directly.

1 Like