In this video, we will add the new mechanics to our obstacle course.
As you can see, we'd changed the layout compared to the previous series.
You can find this updated level in the ObstacleCourse_Part 2 directory,
and go down to ObstacleCourse.tscn.
I'll let you open that one.
We changed the level to adapt it to our new obstacles
which we're going to add.
Now, we can start with a pressure plate and a door.
Expand the obstacles directory, doors.
We're going to start by adding them as children of the obstacles node
as we already have it.
I'm also going to hide everything that adds visual noise.
Click the icon next to the OffCourse node and the Info node.
With the Obstacles node selected,
we can drag and drop a pressure plate first.
The thing that I want to do here just to show you
is to add doors here on the bridges to block the player.
Now, if a door is connected to a pressure plate,
we can open the door by walking on the plate.
But if the door is alone, it's just going to block the player.
We also have a pickup
that allows the player to go through walls and through doors.
We're going to combine these to create a little game loop
or level loop, if you want.
I'm going to press CTRL+Z a couple of times here.
I start with my pressure plate.
Then going to select the plate and I want to add a door as a child of it.
I'm going to select a door horizontal and place it on the bridge.
Now, the way while placing the nodes is not as precise as could be.
We're going to use grid snapping to place them more accurately.
You can press Shift+G
or you can use the icon up there in the toolbar.
If you don't have the settings from previous projects,
you can go to the three dots, Configure Snap,
and ensure that the Grid Steps are 64 by 64,
then click okay.
When I try to click on the pressure plate or the door,
the remaining time is getting in the way.
So I'm going to hide this node as well for now.
Now, I can select the pressure plate.
And when I click and drag, it's going to snap to a grid cell.
You can see that the door moves with the plate due to our setup.
It's possible in Godot to make children move independently from their parent
but that's a bit beyond the scope of this tutorial.
All you have to do is move the plate first,
and then you move the door, and snap it.
You can just click and drag on the nodes
to select and move them quickly, which is quite convenient.
All right, so we have the plate with a connected door.
Now, I want to add doors here,
but I don't want them to be children of the plate
because I just want them to always block the player.
I select the Obstacles parent node,
and then I'm going to drag the door horizontal onto the level
and it's going to snap to the grid.
You can see that it gets added as a child of the obstacles node.
And then same for the door vertical.
I'm going to click and drag it onto the bridge there.
We can now press F6 to play the game.
You can see that we have the animation
that prevents us from quickly testing the level,
which is a little bit inconvenient.
It'd be nice if, at least for testing, we could turn it off.
We can do that by going to the ObstacleCourse script
and click the script icon to open it.
In the ready function, we're going to do two things.
What the start animation does...
I'm going to go back to the animation player to show you.
Is it animates the numbers and then calls the start function.
One thing we can do is at the start of the game,
we move the animation to the end so it hides the number.
And then doing that will not call the start function
so we have to call it manually.
I'm going to go back to the ObstacleCourse script
and at the end of the ready function,
I'm going to get the animation player and call it seek function.
It's going to move the time cursor on the animation timeline
so we could move directly to three seconds
to the end of the animation.
Or you can use the infinite constant in Godot
to say, "Go to the end of the animation."
It's going to be limited by our animation's limit.
The advantage being that this works with any animation in Godot.
And then we're going to call the start function.
We can do that, press F6.
You can see that we can instantly play the game, walk on the plate.
And when we do so, the door opens,
we can quickly go through it and get to the next platform.
Well, we still have the timer running,
so one thing we could do is stop the timer.
But for now, I want us to focus on one issue that we have in there.
It's how we move in front and behind the pressure plate.
This happens because we place the plates in the Obstacles node.
It's a node of type YSort.
So it's going to sort the plate with the player
based on their vertical position.
If I place Godot above the plate, it shows behind it.
If I place Godot below the plate, it's going to show up in front.
We don't want that.
One thing we can do is group these nodes under a new node 2D.
That will cut the Y sorting.
We can add that one as a child of the obstacles.
Press Ctrl+A and add a new node 2D that will call doors, for example.
And then we're going to move the pressure plate and the two doors
into the doors node.
That's one problem solved.
Now, they always show behind the player.
Well, maybe you would want the doors to show up in front or behind the player
but for now, we're going to keep things simple.
The last thing that we want to complete
our little level loop is to place a ghost pickup down there.
So that the player can grab the pickup
and go through the doors and through the obstacles there.
Select the Obstacles node, again.
This time, we go to the pickups directory in the file system dock,
and click and drag the pickup ghost onto the platform.
Place it wherever you feel is good.
You can see I have particles in this video.
We'll add them in the next lessons.
You can now play, go through the door, get the ghost pickup.
If you don't hit the slow zone,
you should be able to pass through the walls.
It's a bit difficult at the moment.
You have to be good at games, which I'm not.
You can see that you can pass in front of the door,
and avoid the push wall and everything.
That's a little level loop done.
I invite you to do the same and fill the level
with a couple of mechanics like these just to have fun, to relax a little bit
before we move on to the other tasks.
One quick tip, if you want to test the mechanics
in a different part of the level, you just move Godot, the character,
to some other place where you're going to put
some other mechanics.
Say I go to my obstacles,
I'm going to add a speed pickup in there.
Or maybe, I'm going to add the speed pickup on this island.
You get it, you go fast, and you have to handle the turns
to get onto this platform.
So I can place Godot on the bridge and go down.
And when I go faster... It's a bit hard to manage the time.
So maybe, you want to place the speed pickup around there.
So you move in a curve and try to enter the bridge horizontally.
You can move Godot in the scene to quickly test your level loops
in different parts of the level.
You can see you have a couple of bridges.
They're all pretty good to place pressure plates and doors.
And a couple of places are good as well to place some pickups.
While filling up the level with those pickups and those doors
is the same thing everytime.
You're going to place some doors, some plates.
You're going to test, move them, and test again, and so on.
Once you are done, you want to move Godot back to the start position up there.
And you want to be sure to go back to the script,
remove these temporary lines of code
and resolve the visibility of the UI nodes.
That will allow us to play the level like normal.
Now, the obstacle course is a bit bigger than before.
So maybe, you want to also adjust the timer's duration.
It was set to 12 seconds, but maybe you want to go up to 15 or 20,
or something like that.
Just to leave the player the time
to explore the level and reach the finish line.
In the next video, we'll add the floating styles that you can see
on the pickups just to make the game feel a tiny bit nicer.
See you there.