Physics.Linecast does not return collider between start and end.

The problem in question description.

Proff 1:

Proff 1 explanation:
We cast a Line from Context (the box that casts lines ) to all points in the scene that satisfy an IF statement provided in the next picture.
Obviously, you can see Line passes through Wall(13) that has tag == Enemy and a valid Box Collider.


So I made a function, getAllVisiblePositions, where first I get AllPositionsInDirection (explanation in code comments) and then for each point in that list, I cast a line and check if it hit the Wall(13), in the picture, at least 2 lines should hit that wall, and make it impossible to be added to list of visible points.
In the console, the TRUE string is not printed, like it never hits the Wall(13).

Number 11 is Layer for the floor, so the line cast ignores it.
Component debugObjectValidity is on every point in sceen.

Am I doing something wrong, or this is a bug?

HI @unity_4XWcnhMEUZ043g, chances are the problem is the layer mask. How did you come up with 11 for the layer mask?

If you are testing objects in only one specific layer, the integer representation of the layer mask will always be a power of 2. So, 11 looks suspect.

The layer mask is not the number of the layer - it is a 1 bit-shifted by the number of the layer.

There are a number of ways to generate a layer mask - I always prefer to set up a public LayerMask variable and then choose the layers I need from the menu that displays for that variable in the inspector.

Otherwise, if you only need to check your raycast against one layer, you can use 1 << number of layer to get the correct layer mask, and either use that directly in your raycast or store it in a variable up front. If you are doing this repeatedly, store it in a variable and use that variable in your linecast call.