In this lecture, we're adding a cinema chain confine so that our player, once they run to the side
of the screen, the camera doesn't move any further.
It is stopped by a collision and we don't see whatever mess is hiding off the side of our screen.
Let's start by adding a little bit more level to our level.
I'm going to click on where where are we over here on my tail palette.
I'm going to highlight all of my background green blocks, make sure that I'm selected on my background
tall.
Matt That's super important.
And we on the brush.
Yep.
And then just paint the area that I think my level is going to be.
Now, it doesn't have to be a rectangle.
I'll do a rectangle just for convenience sake.
In this particular process, I'm probably not going to run down underground.
So I'm going to, let's see, click the eraser and then just erase the background there.
You don't have to.
You can have these things floating around in space, but I think I will keep it nice and tight.
There we go.
So it gives me a little bit extra level that I can add that's larger than the camera.
That's the point of this exercise so that we can try our center, machine, camera and make sure it
all works out.
Next, I'll add a little bit more level.
So now jump over into our platform's tile map.
I'm going to select my rule tile, which for me is this one in the middle here.
So hopefully you remember where yours is hiding.
I'm going to make myself a little bit of level.
Maybe we'll start down below.
We've got a couple of jump jumps to do there and I'll do the outside of my level, so I'll make it very
boxy for this one.
It doesn't have to be boxy.
We can make it all manner of exciting shapes.
But I will do that, make mine boxy a little bit of a roof up here.
So I'll split up the video just as I make a level.
It's not really important what the layout is, just so that we've got an outside that we can bump into.
Now the next step for us is to create a collision that says this is where the camera is going to be
confined to.
So I'm going to click back on my background tile map.
So we're actually on this tile map.
I'm going to add a component which will be a polygon polygon collider, 2d y, a polygon.
Well, if you've got a level that's not exactly a rectangle as we do here, then you need more than
just the four corners.
So in this instance, I'm only going to use the Four Corners, but I'm probably going just means that
we're starting off with that idea that it doesn't just have to be a square or a rectangle.
You can see under our Polygon Collider 2D component, there's an edit collider, click on that and then
drag the collider points probably into the middle of our wall in here.
We don't want the player to see anything on the other side of the wall.
And I accidentally gave myself another point in there.
So one point where are we all the way down here?
This collider came in big, didn't it?
Pop that over there?
It doesn't matter if it's not exactly straight.
Just got to stop the camera from bumping into it.
And this last point, we're just going to pop in line along there.
That should be fine.
Doesn't matter that there's an extra point in there.
It will behave itself.
It just needs to stop the camera from being able to go upwards.
That's its job here.
So we've got that next.
What we need to do is click on our camera.
So you see our follow camera here, which is our virtual camera scroll all the way down.
You can see under extensions, hold that down.
Don't let your mouse go.
Hold it down and have a look around.
There's a bunch more in here than last time I looked, actually, which is really cool.
We're looking for the cinema chain confines, so select that or create that.
Now it's looking for what the bounding shape 2D is.
So we need to give it a shape that contains some collision.
And for us that's going to be our background tile map.
So drag that on over background point and you can see that our collision has turned yellow.
So it's in there permanently.
We can see it.
If it's not quite, it looks a little bit wobbly in there.
That's fine.
We can tweak that later on.
We've got that in here now.
If I click on play, we're probably going to get some nonsense behavior.
Let's see if it pops over into the game.
Yeah.
So I don't know what's going on there, but I'm way off into the ground and that's because we've just
gone and created a collision conflict where we've said the background has collision on it.
We've got our collision box here and the player and the camera, they don't know what's going on because
there's a bumping into each other collision issue going on here.
And this is to do with layers of our collision layers.
And we've talked about this a little bit.
What I'm going to do is click on the player, scroll all the way up, look at the layer at the moment
is default.
So where default, the background is default and that's causing the conflict.
So I want to add a couple of layers in here.
Use a layer eight, I will call player and use a layer nine, I will call background.
Then we'll just jump back over into player will change the layout of player to player.
Why not?
This seems like the right thing to call it.
And then we'll find the background tile map and will change the layout of that to background.
Remember, we're changing the collision layers in here, not the sorting layers.
That's a different thing.
We're changing the collision layers.
And as we've talked about before, if we jump up to edit, find project settings and look for physics,
2D over on the left hand side in the list there you can see down the very bottom we've got this matrix.
We talked about it very briefly before.
Now it becomes a little bit more useful because what we want to say is the background shouldn't be colliding
with anything.
It's just there to look pretty.
It's just in the background.
So let's uncheck all the boxes that background may collide with, may bump into.
You can see our layer collision matrix.
So we don't want background to be colliding with anything else.
That should be all we need to do when we x out of that the player is on a separate layer to the background
and the player and the layer aren't bumping into each other.
But we want the player to be able to collide with all the other things.
Let's run, run, run.
We've given Al sign a machine can finer.
Let's just do it so we can see what's actually going on here.
We'll get the game and the scenes side by side.
I know there's not a lot of real estate in my screen now.
We can see on our scene that the camera gets to the end, touches our collision, which outcome Finer
says is the edge of it, doesn't go any further.
And if we go running all the way down to the right, if I can get him down there, still got a couple
of things to fix in the game.
You can see that the camera stops down the end as well and it fails to do the same and to jump up to
the top.
It's going to be confined up at the top.
So this is a really nice way of saying to the player, Hey, ah, you've reached as far as you're allowed
to go because hey, the camera is saying you can't go any further and it's a good design mechanism to
constrain the player within the world.
Looks a little bit garbage down the bottom there.
I think I would need to give my camera a little bit more view of the bottom.
So I'm just going to show you how to do that.
Very briefly, if we click back on our background tile map, jump over to editing, our polite polygon
collider grabbed the point, drag it down and sideways a little bit, drag it up.
Then you can see this is the process really simple and we don't need to do anything else but are being
baited.
Boom.
I'll just finish this very quickly.
We can click on play that will have updated automatically, I think.
I hope, I believe our collision of where the center machine can finer thinks we're allowed to go to
so that is pretty cool.
So happy with that.
We've added some cool functionality to our camera.
I'll see you in the next lecture.