How to enable a mask for raycasts #1347
-
Hi I was wondering how I would use a mask for raycasting to check against certain layers only. Currently I have the default layers moving and non moving. So if I set the layerMask to 0011 it should check for collisions on both layers.
I've tried doing it this way
But the issue is that if the object im looking for is behind an object on the wrong layer it will return false. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would suggest reading the collision filtering section: https://jrouwe.github.io/JoltPhysics/#collision-filtering Basically, you should be using the BroadPhaseLayerFilter/ObjectLayerFilter interfaces to filter out the hits. The version of |
Beta Was this translation helpful? Give feedback.
I would suggest reading the collision filtering section: https://jrouwe.github.io/JoltPhysics/#collision-filtering
Basically, you should be using the BroadPhaseLayerFilter/ObjectLayerFilter interfaces to filter out the hits. The version of
CastRay
you're using will return the first hit that wasn't filtered, so if the object is 'behind an object' then you will only see the object that comes first unless you filtered the hit out using a filter function. Given that you want to use bitmasks for collision filtering you should probably take a look at ObjectLayerPairFilterMask, ObjectVsBroadPhaseLayerFilterMask and BroadPhaseLayerInterfaceMask.