Raycast layer mask detects collision at weird values?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fishtail
:warning: Old Version Published before Godot 3 was released.

I’m using code to send out a raycast, and for the life of me, I can’t figure out why it will or won’t detect this tilemap I have.

So in the Inspector window of my TileMap, I have bits 0 (value 1) and 1 (value 2) checked, for a total of value 3. I used space.intersect_ray from another body, and set the 4th argument (the layer mask) to 3. It detects. Great!

That’s how I understood it was supposed to work anyway. But then it lost me.

I decided to see what would happen if I changed the value of that layer mask argument in the code. No changes were made to the bit values of the tilemap. The result was that it would detect no matter what number I entered unless it was a multiple of 4.

I tried again, but this time I changed it so the tilemap only had bit 1 checked (value 2). And the result was that it would detect/skip every two numbers starting with 2.
Meaning it…
doesn’t detect: 1, 4, 5, 8, 9, etc.
detects: 2, 3, 6, 7, 10, 11, etc.

What is going on here? I thought that the layer mask had to equal the value of the object collision layer to detect, and wouldn’t otherwise.

Am I misunderstanding how this entire thing works?

I’m using Godot 2.2 alpha, if that matters.