1 00:00:00,000 --> 00:00:02,371 In this video, we'll create Collision Shapes 2 00:00:02,372 --> 00:00:06,583 to prevent our player from walking in the empty space, 3 00:00:06,584 --> 00:00:09,000 outside of the obstacle course. 4 00:00:09,280 --> 00:00:12,860 We have some Collision Shapes for the rocks, for the walls, 5 00:00:12,890 --> 00:00:17,540 which were prepared for you, but we are missing them 6 00:00:17,560 --> 00:00:21,020 around the islands, around the obstacle course. 7 00:00:21,050 --> 00:00:25,914 As we mentioned before, the visuals of a game has nothing to do 8 00:00:25,915 --> 00:00:28,620 with the physical representation of the world. 9 00:00:28,650 --> 00:00:30,371 Unless you have Collision Shapes, 10 00:00:30,471 --> 00:00:33,943 the character can walk freely anywhere. 11 00:00:34,680 --> 00:00:36,620 Let's get started adding them. 12 00:00:36,640 --> 00:00:41,460 We're going to select the Obstacle Course and add a new Static Body 2D node 13 00:00:41,490 --> 00:00:44,700 as a child of it and as a child of the Static Body, 14 00:00:44,701 --> 00:00:48,571 we're going to add a new Collision Polygon 2D. 15 00:00:49,009 --> 00:00:52,140 Three icons appear in the toolbar at the top. 16 00:00:52,170 --> 00:00:55,086 The one on the left allows you to draw points, 17 00:00:55,087 --> 00:00:57,740 and that's the one that we want active. 18 00:00:57,770 --> 00:01:02,180 Then you can click anywhere in the game view to define points, 19 00:01:02,210 --> 00:01:08,380 and once you click on the starting point, you close the Collision Shape. 20 00:01:08,410 --> 00:01:10,999 Before we get drawing, 21 00:01:11,000 --> 00:01:14,210 we just want to talk about the Grid-Snapping. 22 00:01:14,240 --> 00:01:18,199 We set it to 128 by 128. 23 00:01:18,200 --> 00:01:22,089 This is not going to work here because as you can see, 24 00:01:22,090 --> 00:01:27,770 we can't properly block the ledges of our islands, 25 00:01:27,771 --> 00:01:31,986 but we don't want the player to walk over these areas, 26 00:01:32,386 --> 00:01:35,114 so we need to change the Grid-Snapping options. 27 00:01:35,115 --> 00:01:38,260 First, if you don't have Grid-Snapping Active, 28 00:01:38,290 --> 00:01:43,260 you want this blue icon at the top with a magnet to be turned on. 29 00:01:43,290 --> 00:01:48,329 Then click the three dots next to them, and go to Configure Snap. 30 00:01:48,600 --> 00:01:55,285 Instead of 128, we want to set the grid to 64 by 64 pixels, 31 00:01:55,286 --> 00:01:58,620 so you can click in a field, press Control A 32 00:01:58,650 --> 00:02:00,820 and then type the number. 33 00:02:00,850 --> 00:02:03,980 Then press Tab and do the same for the other cell. 34 00:02:04,010 --> 00:02:07,071 Press Enter and be sure to click Okay, 35 00:02:07,072 --> 00:02:11,380 to confirm the new grid step that you want. 36 00:02:11,410 --> 00:02:14,610 From there, we can get creating the Collision Shapes. 37 00:02:14,640 --> 00:02:17,980 It's going to be a bit repetitive, but that's part of the job. 38 00:02:18,010 --> 00:02:21,243 Actually, we have to do that in games from time to time. 39 00:02:21,443 --> 00:02:24,129 You're going to click somewhere in the top left 40 00:02:24,130 --> 00:02:28,220 of the level and then you want to draw straight lines. 41 00:02:28,250 --> 00:02:32,712 This will give us maximum precision when the player collides with them, 42 00:02:32,912 --> 00:02:35,671 and we're going to circle the island like that, 43 00:02:35,672 --> 00:02:38,100 taking the ledges into account, 44 00:02:38,914 --> 00:02:42,940 and we don't have to draw a single Collision Polygon. 45 00:02:42,970 --> 00:02:48,286 We're going to split the level into multiple Collision Polygon 2D 46 00:02:48,287 --> 00:02:52,244 so I'm going to close this one pretty quickly right there. 47 00:02:52,444 --> 00:02:55,860 If you have an edge that's a bit off, no problem. 48 00:02:55,890 --> 00:02:59,743 You can click and drag over a vertex to move it 49 00:03:00,171 --> 00:03:02,702 and clean up the drawing. 50 00:03:02,902 --> 00:03:05,020 When you have one shape done, 51 00:03:05,050 --> 00:03:07,139 if you want to draw the next one, 52 00:03:07,140 --> 00:03:09,600 you need a new Collision Polygon 2D node. 53 00:03:09,601 --> 00:03:14,728 So select your Static Body 2D and add a new Collision Polygon 2D 54 00:03:14,729 --> 00:03:16,886 as a child and you can keep drawing. 55 00:03:17,214 --> 00:03:19,614 You're going to have to repeat that 56 00:03:19,615 --> 00:03:25,610 until you finished drawing all the shapes around your level. 57 00:03:25,640 --> 00:03:27,329 That can be a bit repetitive 58 00:03:27,330 --> 00:03:30,386 but you can put some music in the background when you do this, 59 00:03:30,387 --> 00:03:34,645 and enjoy the flow of just making the level. 60 00:03:35,457 --> 00:03:39,570 I'll let you keep adding your Collision Polygons 2D 61 00:03:39,571 --> 00:03:42,329 as an exercise, I'm going to skip ahead now. 62 00:03:43,052 --> 00:03:47,540 I'm done covering my entire level with Collision Polygons. 63 00:03:47,570 --> 00:03:51,732 I just want to mention this area in the center, near the bridge 64 00:03:51,733 --> 00:03:53,586 that you don't want to forget because 65 00:03:53,587 --> 00:03:55,600 there's a bit of empty space in there. 66 00:03:56,614 --> 00:03:58,882 Don't worry if you don't have exactly 67 00:03:58,883 --> 00:04:03,060 the same number of polygons, the same number of nodes as I do, 68 00:04:03,090 --> 00:04:06,540 what matters is that you cover the entire level. 69 00:04:06,570 --> 00:04:08,198 Now, if you try the game, 70 00:04:08,199 --> 00:04:10,871 you're going to see the character cannot walk 71 00:04:10,872 --> 00:04:13,371 in the empty space anymore. 72 00:04:13,372 --> 00:04:16,740 I'm going to turn off the visible Collision Shapes 73 00:04:16,741 --> 00:04:19,344 just to enjoy the view a little bit more 74 00:04:19,345 --> 00:04:22,128 and I just want to mention that, 75 00:04:23,471 --> 00:04:27,380 this is not necessarily how you would do it, in a complete game. 76 00:04:27,410 --> 00:04:33,285 This is good for prototyping and as you add many levels to a game, 77 00:04:33,286 --> 00:04:35,871 you would want a more systematic solution, 78 00:04:35,872 --> 00:04:39,286 probably using code but this gets a lot more complex 79 00:04:39,287 --> 00:04:43,740 and this is why we don't necessarily cover this, right now. 80 00:04:43,770 --> 00:04:47,643 When you're prototyping, you want to make very specific levels, 81 00:04:47,644 --> 00:04:51,101 ensure that all the mechanics, the game feel work. 82 00:04:51,229 --> 00:04:57,613 It's mostly once you solidify that you want to move on to automated solutions 83 00:04:57,614 --> 00:04:59,314 because automating things, 84 00:04:59,443 --> 00:05:04,286 takes time to code and you don't want to waste that precious time. 85 00:05:04,443 --> 00:05:06,229 With that, in the next lesson, 86 00:05:06,230 --> 00:05:11,040 we'll move on to the game's UI and Win and Lose Conditions.