In this video, we'll create Collision Shapes
to prevent our player from walking in the empty space,
outside of the obstacle course.
We have some Collision Shapes for the rocks, for the walls,
which were prepared for you, but we are missing them
around the islands, around the obstacle course.
As we mentioned before, the visuals of a game has nothing to do
with the physical representation of the world.
Unless you have Collision Shapes,
the character can walk freely anywhere.
Let's get started adding them.
We're going to select the Obstacle Course and add a new Static Body 2D node
as a child of it and as a child of the Static Body,
we're going to add a new Collision Polygon 2D.
Three icons appear in the toolbar at the top.
The one on the left allows you to draw points,
and that's the one that we want active.
Then you can click anywhere in the game view to define points,
and once you click on the starting point, you close the Collision Shape.
Before we get drawing,
we just want to talk about the Grid-Snapping.
We set it to 128 by 128.
This is not going to work here because as you can see,
we can't properly block the ledges of our islands,
but we don't want the player to walk over these areas,
so we need to change the Grid-Snapping options.
First, if you don't have Grid-Snapping Active,
you want this blue icon at the top with a magnet to be turned on.
Then click the three dots next to them, and go to Configure Snap.
Instead of 128, we want to set the grid to 64 by 64 pixels,
so you can click in a field, press Control A
and then type the number.
Then press Tab and do the same for the other cell.
Press Enter and be sure to click Okay,
to confirm the new grid step that you want.
From there, we can get creating the Collision Shapes.
It's going to be a bit repetitive, but that's part of the job.
Actually, we have to do that in games from time to time.
You're going to click somewhere in the top left
of the level and then you want to draw straight lines.
This will give us maximum precision when the player collides with them,
and we're going to circle the island like that,
taking the ledges into account,
and we don't have to draw a single Collision Polygon.
We're going to split the level into multiple Collision Polygon 2D
so I'm going to close this one pretty quickly right there.
If you have an edge that's a bit off, no problem.
You can click and drag over a vertex to move it
and clean up the drawing.
When you have one shape done,
if you want to draw the next one,
you need a new Collision Polygon 2D node.
So select your Static Body 2D and add a new Collision Polygon 2D
as a child and you can keep drawing.
You're going to have to repeat that
until you finished drawing all the shapes around your level.
That can be a bit repetitive
but you can put some music in the background when you do this,
and enjoy the flow of just making the level.
I'll let you keep adding your Collision Polygons 2D
as an exercise, I'm going to skip ahead now.
I'm done covering my entire level with Collision Polygons.
I just want to mention this area in the center, near the bridge
that you don't want to forget because
there's a bit of empty space in there.
Don't worry if you don't have exactly
the same number of polygons, the same number of nodes as I do,
what matters is that you cover the entire level.
Now, if you try the game,
you're going to see the character cannot walk
in the empty space anymore.
I'm going to turn off the visible Collision Shapes
just to enjoy the view a little bit more
and I just want to mention that,
this is not necessarily how you would do it, in a complete game.
This is good for prototyping and as you add many levels to a game,
you would want a more systematic solution,
probably using code but this gets a lot more complex
and this is why we don't necessarily cover this, right now.
When you're prototyping, you want to make very specific levels,
ensure that all the mechanics, the game feel work.
It's mostly once you solidify that you want to move on to automated solutions
because automating things,
takes time to code and you don't want to waste that precious time.
With that, in the next lesson,
we'll move on to the game's UI and Win and Lose Conditions.