Physics layers and masks can be a bit difficult to understand.
So we made this little demo where you can toggle them on different physics bodies
to see how they work.
First, you can find the demo by pressing Ctrl + Shift + O
and you look for LayersMasksDemo.tscn.
Then press F6 to run it,
and I want to run you through some examples here.
Let's start with the player and the rock that you can see in the right column.
When I move towards the rock, the character is going to push it.
Now, this is because the player has the mask number 2
and rock has the layer number 2.
If I turn off the mask number 2 on the player,
I now pass through the rock.
I can restore the mask to push the rock.
Then if I remove layer two from the rock, I pass through it again.
Why?
Because I mask layer two on the player, but the rock is on no layer,
so nothing can collide with it.
What if this time I turn on mask one on the rock?
The player is on physics layer one.
Well, then my player can push the rock again.
So you can see how the mask allows for an interaction between two physics bodies.
As long as one has a layer and the other has a matching mask,
they are going to collide.
It works this way in Godot 3.
Similarly, here, we have a switch that toggles the door open
when it's being pressed.
The switch is on layer three and it masks layer one and two.
If I turn off the layer three here, the door closes.
Why?
Because our rock has mask three.
This is what allows it to detect the switch.
So if I turn on layer three, the switch gets pressed, the door opens.
If I turn off layer three, the door closes.
Similarly, if I have a layer three, but I turn off mask three on the rock,
the door closes.
But the switch has its mask to one and two.
This allows it to detect the player walking
on the switch right now.
If I put the rock on layer one or on layer two,
the door opens accordingly.
Similarly, with a pickup, the pickup is on layer four,
if I go back to the player, turn off mask four,
I can't pick up the gems.
But if I turn the mask four back on, I can now collect the gems.
So I invite you to play a bit with this demo.
Hopefully, the demonstration helps to make a little more sense of how these work.
And by switching the things,
you should get a more intuitive understanding
of these two confusing properties.
With that, I'll see you in the next one. Bye-bye.