Problem with raycasting using a layer mask

Physics.Raycast(originPos, (targetPos - originPos), out hit, masks.VisibilityCastMask);

My raycast line

The mask in question is: public static LayerMask VisibilityCastMask = 65535;

By my understanding, this should hit layers 0-15, and ignore objects on all subsequent layers. My player object (and all children) is on layer 17, but it is still blocking this raycast.


Your code is wrong. It should be like this:

public const int VisibilityCastMask = 65535;
Physics.Raycast(originPos, (targetPos - originPos), out hit, VisibilityCastMask);

But I think you should use LineCast, it will only check on a line from originPos to targetPos.

turns out i was using the wrong overload