1 00:00:00,571 --> 00:00:03,856 Physics layers and masks can be a bit difficult to understand. 2 00:00:03,857 --> 00:00:09,586 So we made this little demo where you can toggle them on different physics bodies 3 00:00:09,587 --> 00:00:12,071 to see how they work. 4 00:00:12,243 --> 00:00:16,200 First, you can find the demo by pressing Ctrl + Shift + O 5 00:00:16,201 --> 00:00:21,114 and you look for LayersMasksDemo.tscn. 6 00:00:22,186 --> 00:00:24,243 Then press F6 to run it, 7 00:00:24,329 --> 00:00:27,257 and I want to run you through some examples here. 8 00:00:27,586 --> 00:00:31,857 Let's start with the player and the rock that you can see in the right column. 9 00:00:32,357 --> 00:00:35,857 When I move towards the rock, the character is going to push it. 10 00:00:36,086 --> 00:00:40,662 Now, this is because the player has the mask number 2 11 00:00:40,663 --> 00:00:43,248 and rock has the layer number 2. 12 00:00:43,486 --> 00:00:46,129 If I turn off the mask number 2 on the player, 13 00:00:46,130 --> 00:00:48,357 I now pass through the rock. 14 00:00:49,171 --> 00:00:51,757 I can restore the mask to push the rock. 15 00:00:53,100 --> 00:00:59,200 Then if I remove layer two from the rock, I pass through it again. 16 00:00:59,229 --> 00:00:59,778 Why? 17 00:00:59,779 --> 00:01:04,213 Because I mask layer two on the player, but the rock is on no layer, 18 00:01:04,214 --> 00:01:06,500 so nothing can collide with it. 19 00:01:07,329 --> 00:01:12,070 What if this time I turn on mask one on the rock? 20 00:01:12,071 --> 00:01:14,571 The player is on physics layer one. 21 00:01:14,786 --> 00:01:18,400 Well, then my player can push the rock again. 22 00:01:18,500 --> 00:01:25,114 So you can see how the mask allows for an interaction between two physics bodies. 23 00:01:25,115 --> 00:01:29,970 As long as one has a layer and the other has a matching mask, 24 00:01:29,971 --> 00:01:31,529 they are going to collide. 25 00:01:31,530 --> 00:01:34,143 It works this way in Godot 3. 26 00:01:34,600 --> 00:01:39,386 Similarly, here, we have a switch that toggles the door open 27 00:01:39,387 --> 00:01:41,172 when it's being pressed. 28 00:01:41,300 --> 00:01:45,343 The switch is on layer three and it masks layer one and two. 29 00:01:45,344 --> 00:01:49,886 If I turn off the layer three here, the door closes. 30 00:01:49,887 --> 00:01:50,886 Why? 31 00:01:51,029 --> 00:01:53,929 Because our rock has mask three. 32 00:01:53,930 --> 00:01:56,914 This is what allows it to detect the switch. 33 00:01:56,915 --> 00:02:01,014 So if I turn on layer three, the switch gets pressed, the door opens. 34 00:02:01,015 --> 00:02:04,270 If I turn off layer three, the door closes. 35 00:02:04,271 --> 00:02:09,275 Similarly, if I have a layer three, but I turn off mask three on the rock, 36 00:02:09,276 --> 00:02:10,800 the door closes. 37 00:02:11,714 --> 00:02:15,800 But the switch has its mask to one and two. 38 00:02:15,801 --> 00:02:18,657 This allows it to detect the player walking 39 00:02:18,658 --> 00:02:20,243 on the switch right now. 40 00:02:20,486 --> 00:02:24,671 If I put the rock on layer one or on layer two, 41 00:02:24,672 --> 00:02:27,157 the door opens accordingly. 42 00:02:28,557 --> 00:02:31,571 Similarly, with a pickup, the pickup is on layer four, 43 00:02:31,572 --> 00:02:35,829 if I go back to the player, turn off mask four, 44 00:02:35,900 --> 00:02:38,471 I can't pick up the gems. 45 00:02:38,472 --> 00:02:45,857 But if I turn the mask four back on, I can now collect the gems. 46 00:02:46,143 --> 00:02:48,871 So I invite you to play a bit with this demo. 47 00:02:48,872 --> 00:02:54,756 Hopefully, the demonstration helps to make a little more sense of how these work. 48 00:02:54,757 --> 00:02:57,114 And by switching the things, 49 00:02:57,115 --> 00:03:00,629 you should get a more intuitive understanding 50 00:03:00,729 --> 00:03:03,614 of these two confusing properties. 51 00:03:03,814 --> 00:03:06,729 With that, I'll see you in the next one. Bye-bye.