1 00:00:00,000 --> 00:00:04,100 In this video, we will add the new mechanics to our obstacle course. 2 00:00:04,414 --> 00:00:08,529 As you can see, we'd changed the layout compared to the previous series. 3 00:00:08,530 --> 00:00:12,500 You can find this updated level in the ObstacleCourse_Part 2 directory, 4 00:00:12,729 --> 00:00:15,600 and go down to ObstacleCourse.tscn. 5 00:00:15,714 --> 00:00:17,443 I'll let you open that one. 6 00:00:17,843 --> 00:00:22,900 We changed the level to adapt it to our new obstacles 7 00:00:22,901 --> 00:00:24,186 which we're going to add. 8 00:00:24,187 --> 00:00:28,329 Now, we can start with a pressure plate and a door. 9 00:00:28,414 --> 00:00:31,729 Expand the obstacles directory, doors. 10 00:00:32,029 --> 00:00:36,714 We're going to start by adding them as children of the obstacles node 11 00:00:36,715 --> 00:00:38,057 as we already have it. 12 00:00:38,229 --> 00:00:42,057 I'm also going to hide everything that adds visual noise. 13 00:00:42,543 --> 00:00:48,800 Click the icon next to the OffCourse node and the Info node. 14 00:00:48,829 --> 00:00:51,500 With the Obstacles node selected, 15 00:00:51,571 --> 00:00:54,843 we can drag and drop a pressure plate first. 16 00:00:55,290 --> 00:00:57,929 The thing that I want to do here just to show you 17 00:00:57,930 --> 00:01:05,129 is to add doors here on the bridges to block the player. 18 00:01:05,257 --> 00:01:08,185 Now, if a door is connected to a pressure plate, 19 00:01:08,385 --> 00:01:10,757 we can open the door by walking on the plate. 20 00:01:10,758 --> 00:01:14,414 But if the door is alone, it's just going to block the player. 21 00:01:14,671 --> 00:01:17,113 We also have a pickup 22 00:01:17,114 --> 00:01:21,100 that allows the player to go through walls and through doors. 23 00:01:21,130 --> 00:01:25,571 We're going to combine these to create a little game loop 24 00:01:25,572 --> 00:01:27,329 or level loop, if you want. 25 00:01:28,090 --> 00:01:31,200 I'm going to press CTRL+Z a couple of times here. 26 00:01:31,543 --> 00:01:33,529 I start with my pressure plate. 27 00:01:33,943 --> 00:01:40,386 Then going to select the plate and I want to add a door as a child of it. 28 00:01:40,814 --> 00:01:46,029 I'm going to select a door horizontal and place it on the bridge. 29 00:01:46,743 --> 00:01:51,714 Now, the way while placing the nodes is not as precise as could be. 30 00:01:51,757 --> 00:01:56,129 We're going to use grid snapping to place them more accurately. 31 00:01:56,300 --> 00:01:57,914 You can press Shift+G 32 00:01:58,143 --> 00:02:02,186 or you can use the icon up there in the toolbar. 33 00:02:02,714 --> 00:02:06,213 If you don't have the settings from previous projects, 34 00:02:06,357 --> 00:02:09,186 you can go to the three dots, Configure Snap, 35 00:02:09,187 --> 00:02:13,186 and ensure that the Grid Steps are 64 by 64, 36 00:02:13,187 --> 00:02:14,500 then click okay. 37 00:02:14,800 --> 00:02:18,286 When I try to click on the pressure plate or the door, 38 00:02:18,287 --> 00:02:20,929 the remaining time is getting in the way. 39 00:02:20,930 --> 00:02:23,986 So I'm going to hide this node as well for now. 40 00:02:24,686 --> 00:02:26,600 Now, I can select the pressure plate. 41 00:02:26,601 --> 00:02:31,214 And when I click and drag, it's going to snap to a grid cell. 42 00:02:31,800 --> 00:02:35,900 You can see that the door moves with the plate due to our setup. 43 00:02:35,986 --> 00:02:40,157 It's possible in Godot to make children move independently from their parent 44 00:02:40,158 --> 00:02:43,229 but that's a bit beyond the scope of this tutorial. 45 00:02:43,743 --> 00:02:45,986 All you have to do is move the plate first, 46 00:02:45,987 --> 00:02:48,514 and then you move the door, and snap it. 47 00:02:49,957 --> 00:02:51,986 You can just click and drag on the nodes 48 00:02:52,071 --> 00:02:56,271 to select and move them quickly, which is quite convenient. 49 00:02:56,629 --> 00:02:59,214 All right, so we have the plate with a connected door. 50 00:02:59,286 --> 00:03:01,656 Now, I want to add doors here, 51 00:03:01,657 --> 00:03:04,400 but I don't want them to be children of the plate 52 00:03:04,401 --> 00:03:07,057 because I just want them to always block the player. 53 00:03:07,486 --> 00:03:09,600 I select the Obstacles parent node, 54 00:03:09,601 --> 00:03:13,429 and then I'm going to drag the door horizontal onto the level 55 00:03:13,500 --> 00:03:15,043 and it's going to snap to the grid. 56 00:03:15,157 --> 00:03:18,957 You can see that it gets added as a child of the obstacles node. 57 00:03:19,143 --> 00:03:21,314 And then same for the door vertical. 58 00:03:21,315 --> 00:03:24,800 I'm going to click and drag it onto the bridge there. 59 00:03:25,130 --> 00:03:27,757 We can now press F6 to play the game. 60 00:03:28,143 --> 00:03:30,314 You can see that we have the animation 61 00:03:30,315 --> 00:03:33,171 that prevents us from quickly testing the level, 62 00:03:33,172 --> 00:03:35,329 which is a little bit inconvenient. 63 00:03:35,457 --> 00:03:39,643 It'd be nice if, at least for testing, we could turn it off. 64 00:03:40,029 --> 00:03:43,114 We can do that by going to the ObstacleCourse script 65 00:03:43,115 --> 00:03:46,029 and click the script icon to open it. 66 00:03:46,471 --> 00:03:49,771 In the ready function, we're going to do two things. 67 00:03:50,486 --> 00:03:53,060 What the start animation does... 68 00:03:53,061 --> 00:03:55,486 I'm going to go back to the animation player to show you. 69 00:03:56,600 --> 00:04:01,057 Is it animates the numbers and then calls the start function. 70 00:04:01,357 --> 00:04:04,257 One thing we can do is at the start of the game, 71 00:04:04,258 --> 00:04:09,957 we move the animation to the end so it hides the number. 72 00:04:10,186 --> 00:04:13,586 And then doing that will not call the start function 73 00:04:13,587 --> 00:04:15,300 so we have to call it manually. 74 00:04:15,443 --> 00:04:17,914 I'm going to go back to the ObstacleCourse script 75 00:04:17,915 --> 00:04:20,386 and at the end of the ready function, 76 00:04:20,986 --> 00:04:25,980 I'm going to get the animation player and call it seek function. 77 00:04:25,981 --> 00:04:29,900 It's going to move the time cursor on the animation timeline 78 00:04:30,143 --> 00:04:33,428 so we could move directly to three seconds 79 00:04:33,429 --> 00:04:34,857 to the end of the animation. 80 00:04:34,858 --> 00:04:38,757 Or you can use the infinite constant in Godot 81 00:04:38,758 --> 00:04:41,943 to say, "Go to the end of the animation." 82 00:04:42,143 --> 00:04:46,100 It's going to be limited by our animation's limit. 83 00:04:46,101 --> 00:04:50,629 The advantage being that this works with any animation in Godot. 84 00:04:51,280 --> 00:04:54,214 And then we're going to call the start function. 85 00:04:55,071 --> 00:04:57,028 We can do that, press F6. 86 00:04:57,029 --> 00:05:00,757 You can see that we can instantly play the game, walk on the plate. 87 00:05:00,758 --> 00:05:04,229 And when we do so, the door opens, 88 00:05:04,230 --> 00:05:09,886 we can quickly go through it and get to the next platform. 89 00:05:09,887 --> 00:05:11,671 Well, we still have the timer running, 90 00:05:11,672 --> 00:05:14,086 so one thing we could do is stop the timer. 91 00:05:14,087 --> 00:05:19,900 But for now, I want us to focus on one issue that we have in there. 92 00:05:19,901 --> 00:05:24,557 It's how we move in front and behind the pressure plate. 93 00:05:26,171 --> 00:05:31,643 This happens because we place the plates in the Obstacles node. 94 00:05:31,771 --> 00:05:33,815 It's a node of type YSort. 95 00:05:33,816 --> 00:05:36,457 So it's going to sort the plate with the player 96 00:05:36,586 --> 00:05:38,786 based on their vertical position. 97 00:05:38,787 --> 00:05:42,471 If I place Godot above the plate, it shows behind it. 98 00:05:42,629 --> 00:05:48,114 If I place Godot below the plate, it's going to show up in front. 99 00:05:48,730 --> 00:05:49,780 We don't want that. 100 00:05:49,800 --> 00:05:55,257 One thing we can do is group these nodes under a new node 2D. 101 00:05:55,258 --> 00:05:59,114 That will cut the Y sorting. 102 00:05:59,714 --> 00:06:02,342 We can add that one as a child of the obstacles. 103 00:06:02,343 --> 00:06:10,229 Press Ctrl+A and add a new node 2D that will call doors, for example. 104 00:06:11,770 --> 00:06:15,200 And then we're going to move the pressure plate and the two doors 105 00:06:15,201 --> 00:06:17,171 into the doors node. 106 00:06:17,429 --> 00:06:19,171 That's one problem solved. 107 00:06:19,172 --> 00:06:21,986 Now, they always show behind the player. 108 00:06:22,229 --> 00:06:26,242 Well, maybe you would want the doors to show up in front or behind the player 109 00:06:26,243 --> 00:06:29,757 but for now, we're going to keep things simple. 110 00:06:30,143 --> 00:06:32,057 The last thing that we want to complete 111 00:06:32,058 --> 00:06:36,728 our little level loop is to place a ghost pickup down there. 112 00:06:36,729 --> 00:06:38,886 So that the player can grab the pickup 113 00:06:38,887 --> 00:06:42,400 and go through the doors and through the obstacles there. 114 00:06:43,614 --> 00:06:46,039 Select the Obstacles node, again. 115 00:06:46,040 --> 00:06:50,143 This time, we go to the pickups directory in the file system dock, 116 00:06:50,414 --> 00:06:53,814 and click and drag the pickup ghost onto the platform. 117 00:06:53,815 --> 00:06:57,029 Place it wherever you feel is good. 118 00:06:57,030 --> 00:06:59,358 You can see I have particles in this video. 119 00:06:59,359 --> 00:07:01,571 We'll add them in the next lessons. 120 00:07:02,114 --> 00:07:06,114 You can now play, go through the door, get the ghost pickup. 121 00:07:06,400 --> 00:07:09,457 If you don't hit the slow zone, 122 00:07:09,458 --> 00:07:12,229 you should be able to pass through the walls. 123 00:07:12,230 --> 00:07:13,957 It's a bit difficult at the moment. 124 00:07:13,958 --> 00:07:18,257 You have to be good at games, which I'm not. 125 00:07:18,800 --> 00:07:21,157 You can see that you can pass in front of the door, 126 00:07:21,158 --> 00:07:23,729 and avoid the push wall and everything. 127 00:07:24,643 --> 00:07:27,400 That's a little level loop done. 128 00:07:27,529 --> 00:07:31,370 I invite you to do the same and fill the level 129 00:07:31,371 --> 00:07:36,529 with a couple of mechanics like these just to have fun, to relax a little bit 130 00:07:36,530 --> 00:07:38,871 before we move on to the other tasks. 131 00:07:39,457 --> 00:07:43,414 One quick tip, if you want to test the mechanics 132 00:07:43,415 --> 00:07:47,485 in a different part of the level, you just move Godot, the character, 133 00:07:47,486 --> 00:07:49,677 to some other place where you're going to put 134 00:07:49,678 --> 00:07:50,720 some other mechanics. 135 00:07:50,721 --> 00:07:52,829 Say I go to my obstacles, 136 00:07:53,001 --> 00:07:56,571 I'm going to add a speed pickup in there. 137 00:07:57,386 --> 00:08:01,229 Or maybe, I'm going to add the speed pickup on this island. 138 00:08:02,529 --> 00:08:06,186 You get it, you go fast, and you have to handle the turns 139 00:08:06,305 --> 00:08:07,943 to get onto this platform. 140 00:08:08,586 --> 00:08:12,057 So I can place Godot on the bridge and go down. 141 00:08:12,290 --> 00:08:14,885 And when I go faster... It's a bit hard to manage the time. 142 00:08:14,886 --> 00:08:19,900 So maybe, you want to place the speed pickup around there. 143 00:08:20,090 --> 00:08:25,500 So you move in a curve and try to enter the bridge horizontally. 144 00:08:26,614 --> 00:08:32,343 You can move Godot in the scene to quickly test your level loops 145 00:08:32,344 --> 00:08:34,386 in different parts of the level. 146 00:08:34,850 --> 00:08:36,643 You can see you have a couple of bridges. 147 00:08:36,686 --> 00:08:41,014 They're all pretty good to place pressure plates and doors. 148 00:08:41,015 --> 00:08:46,443 And a couple of places are good as well to place some pickups. 149 00:08:48,480 --> 00:08:51,843 While filling up the level with those pickups and those doors 150 00:08:51,844 --> 00:08:53,899 is the same thing everytime. 151 00:08:53,900 --> 00:08:56,229 You're going to place some doors, some plates. 152 00:08:56,230 --> 00:09:00,414 You're going to test, move them, and test again, and so on. 153 00:09:00,843 --> 00:09:06,914 Once you are done, you want to move Godot back to the start position up there. 154 00:09:07,114 --> 00:09:09,157 And you want to be sure to go back to the script, 155 00:09:09,357 --> 00:09:12,886 remove these temporary lines of code 156 00:09:13,257 --> 00:09:16,971 and resolve the visibility of the UI nodes. 157 00:09:18,257 --> 00:09:21,114 That will allow us to play the level like normal. 158 00:09:21,186 --> 00:09:25,229 Now, the obstacle course is a bit bigger than before. 159 00:09:25,429 --> 00:09:29,529 So maybe, you want to also adjust the timer's duration. 160 00:09:29,614 --> 00:09:34,919 It was set to 12 seconds, but maybe you want to go up to 15 or 20, 161 00:09:34,920 --> 00:09:36,314 or something like that. 162 00:09:36,315 --> 00:09:38,600 Just to leave the player the time 163 00:09:38,601 --> 00:09:41,757 to explore the level and reach the finish line. 164 00:09:41,857 --> 00:09:46,357 In the next video, we'll add the floating styles that you can see 165 00:09:46,358 --> 00:09:51,039 on the pickups just to make the game feel a tiny bit nicer. 166 00:09:51,040 --> 00:09:51,971 See you there.