1
00:00:03,090 --> 00:00:08,550
In this lecture, we're adding a cinema chain confine so that our player, once they run to the side

2
00:00:08,550 --> 00:00:10,710
of the screen, the camera doesn't move any further.

3
00:00:10,710 --> 00:00:15,920
It is stopped by a collision and we don't see whatever mess is hiding off the side of our screen.

4
00:00:15,930 --> 00:00:18,330
Let's start by adding a little bit more level to our level.

5
00:00:18,330 --> 00:00:21,840
I'm going to click on where where are we over here on my tail palette.

6
00:00:21,840 --> 00:00:28,050
I'm going to highlight all of my background green blocks, make sure that I'm selected on my background

7
00:00:28,050 --> 00:00:28,330
tall.

8
00:00:28,350 --> 00:00:29,850
Matt That's super important.

9
00:00:29,850 --> 00:00:30,590
And we on the brush.

10
00:00:30,600 --> 00:00:30,780
Yep.

11
00:00:30,780 --> 00:00:33,660
And then just paint the area that I think my level is going to be.

12
00:00:33,660 --> 00:00:35,070
Now, it doesn't have to be a rectangle.

13
00:00:35,070 --> 00:00:37,710
I'll do a rectangle just for convenience sake.

14
00:00:37,710 --> 00:00:41,700
In this particular process, I'm probably not going to run down underground.

15
00:00:41,700 --> 00:00:46,410
So I'm going to, let's see, click the eraser and then just erase the background there.

16
00:00:46,410 --> 00:00:47,010
You don't have to.

17
00:00:47,040 --> 00:00:51,210
You can have these things floating around in space, but I think I will keep it nice and tight.

18
00:00:51,480 --> 00:00:52,170
There we go.

19
00:00:52,170 --> 00:00:56,220
So it gives me a little bit extra level that I can add that's larger than the camera.

20
00:00:56,220 --> 00:01:00,600
That's the point of this exercise so that we can try our center, machine, camera and make sure it

21
00:01:00,600 --> 00:01:01,230
all works out.

22
00:01:01,260 --> 00:01:03,000
Next, I'll add a little bit more level.

23
00:01:03,000 --> 00:01:06,240
So now jump over into our platform's tile map.

24
00:01:06,270 --> 00:01:09,630
I'm going to select my rule tile, which for me is this one in the middle here.

25
00:01:09,630 --> 00:01:11,610
So hopefully you remember where yours is hiding.

26
00:01:11,610 --> 00:01:13,380
I'm going to make myself a little bit of level.

27
00:01:13,380 --> 00:01:14,730
Maybe we'll start down below.

28
00:01:14,730 --> 00:01:20,040
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

29
00:01:20,040 --> 00:01:21,270
boxy for this one.

30
00:01:21,300 --> 00:01:22,770
It doesn't have to be boxy.

31
00:01:22,770 --> 00:01:25,200
We can make it all manner of exciting shapes.

32
00:01:25,200 --> 00:01:30,420
But I will do that, make mine boxy a little bit of a roof up here.

33
00:01:30,510 --> 00:01:32,580
So I'll split up the video just as I make a level.

34
00:01:32,580 --> 00:01:38,220
It's not really important what the layout is, just so that we've got an outside that we can bump into.

35
00:01:40,740 --> 00:01:45,510
Now the next step for us is to create a collision that says this is where the camera is going to be

36
00:01:45,510 --> 00:01:46,200
confined to.

37
00:01:46,230 --> 00:01:48,870
So I'm going to click back on my background tile map.

38
00:01:48,870 --> 00:01:50,390
So we're actually on this tile map.

39
00:01:50,400 --> 00:01:57,150
I'm going to add a component which will be a polygon polygon collider, 2d y, a polygon.

40
00:01:57,180 --> 00:02:02,400
Well, if you've got a level that's not exactly a rectangle as we do here, then you need more than

41
00:02:02,400 --> 00:02:03,810
just the four corners.

42
00:02:03,820 --> 00:02:07,800
So in this instance, I'm only going to use the Four Corners, but I'm probably going just means that

43
00:02:07,800 --> 00:02:11,700
we're starting off with that idea that it doesn't just have to be a square or a rectangle.

44
00:02:11,730 --> 00:02:17,310
You can see under our Polygon Collider 2D component, there's an edit collider, click on that and then

45
00:02:17,310 --> 00:02:22,310
drag the collider points probably into the middle of our wall in here.

46
00:02:22,320 --> 00:02:24,690
We don't want the player to see anything on the other side of the wall.

47
00:02:24,690 --> 00:02:27,050
And I accidentally gave myself another point in there.

48
00:02:27,060 --> 00:02:29,040
So one point where are we all the way down here?

49
00:02:29,190 --> 00:02:30,810
This collider came in big, didn't it?

50
00:02:31,110 --> 00:02:32,490
Pop that over there?

51
00:02:32,760 --> 00:02:35,640
It doesn't matter if it's not exactly straight.

52
00:02:35,640 --> 00:02:37,650
Just got to stop the camera from bumping into it.

53
00:02:37,650 --> 00:02:40,590
And this last point, we're just going to pop in line along there.

54
00:02:40,590 --> 00:02:41,130
That should be fine.

55
00:02:41,140 --> 00:02:42,750
Doesn't matter that there's an extra point in there.

56
00:02:42,750 --> 00:02:43,680
It will behave itself.

57
00:02:43,710 --> 00:02:45,960
It just needs to stop the camera from being able to go upwards.

58
00:02:45,960 --> 00:02:46,860
That's its job here.

59
00:02:46,860 --> 00:02:47,850
So we've got that next.

60
00:02:47,850 --> 00:02:50,190
What we need to do is click on our camera.

61
00:02:50,220 --> 00:02:53,730
So you see our follow camera here, which is our virtual camera scroll all the way down.

62
00:02:53,730 --> 00:02:56,370
You can see under extensions, hold that down.

63
00:02:56,370 --> 00:02:57,540
Don't let your mouse go.

64
00:02:57,570 --> 00:02:58,860
Hold it down and have a look around.

65
00:02:58,860 --> 00:03:02,280
There's a bunch more in here than last time I looked, actually, which is really cool.

66
00:03:02,280 --> 00:03:06,750
We're looking for the cinema chain confines, so select that or create that.

67
00:03:06,750 --> 00:03:09,270
Now it's looking for what the bounding shape 2D is.

68
00:03:09,270 --> 00:03:12,060
So we need to give it a shape that contains some collision.

69
00:03:12,060 --> 00:03:14,820
And for us that's going to be our background tile map.

70
00:03:14,820 --> 00:03:19,740
So drag that on over background point and you can see that our collision has turned yellow.

71
00:03:19,740 --> 00:03:21,060
So it's in there permanently.

72
00:03:21,060 --> 00:03:21,510
We can see it.

73
00:03:21,510 --> 00:03:23,760
If it's not quite, it looks a little bit wobbly in there.

74
00:03:23,760 --> 00:03:24,180
That's fine.

75
00:03:24,180 --> 00:03:25,920
We can tweak that later on.

76
00:03:25,920 --> 00:03:26,880
We've got that in here now.

77
00:03:26,880 --> 00:03:29,670
If I click on play, we're probably going to get some nonsense behavior.

78
00:03:29,850 --> 00:03:31,710
Let's see if it pops over into the game.

79
00:03:31,710 --> 00:03:32,100
Yeah.

80
00:03:32,100 --> 00:03:36,330
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

81
00:03:36,330 --> 00:03:42,990
gone and created a collision conflict where we've said the background has collision on it.

82
00:03:42,990 --> 00:03:47,190
We've got our collision box here and the player and the camera, they don't know what's going on because

83
00:03:47,190 --> 00:03:50,280
there's a bumping into each other collision issue going on here.

84
00:03:50,280 --> 00:03:53,730
And this is to do with layers of our collision layers.

85
00:03:53,730 --> 00:03:55,290
And we've talked about this a little bit.

86
00:03:55,290 --> 00:04:00,270
What I'm going to do is click on the player, scroll all the way up, look at the layer at the moment

87
00:04:00,270 --> 00:04:01,080
is default.

88
00:04:01,080 --> 00:04:04,800
So where default, the background is default and that's causing the conflict.

89
00:04:04,800 --> 00:04:06,690
So I want to add a couple of layers in here.

90
00:04:06,720 --> 00:04:12,330
Use a layer eight, I will call player and use a layer nine, I will call background.

91
00:04:13,250 --> 00:04:19,670
Then we'll just jump back over into player will change the layout of player to player.

92
00:04:19,700 --> 00:04:20,320
Why not?

93
00:04:20,490 --> 00:04:21,920
This seems like the right thing to call it.

94
00:04:21,920 --> 00:04:26,720
And then we'll find the background tile map and will change the layout of that to background.

95
00:04:26,720 --> 00:04:31,760
Remember, we're changing the collision layers in here, not the sorting layers.

96
00:04:31,760 --> 00:04:32,600
That's a different thing.

97
00:04:32,600 --> 00:04:34,100
We're changing the collision layers.

98
00:04:34,100 --> 00:04:39,140
And as we've talked about before, if we jump up to edit, find project settings and look for physics,

99
00:04:39,140 --> 00:04:44,210
2D over on the left hand side in the list there you can see down the very bottom we've got this matrix.

100
00:04:44,210 --> 00:04:45,860
We talked about it very briefly before.

101
00:04:45,860 --> 00:04:50,990
Now it becomes a little bit more useful because what we want to say is the background shouldn't be colliding

102
00:04:50,990 --> 00:04:51,650
with anything.

103
00:04:51,650 --> 00:04:53,120
It's just there to look pretty.

104
00:04:53,120 --> 00:04:54,500
It's just in the background.

105
00:04:54,500 --> 00:04:59,000
So let's uncheck all the boxes that background may collide with, may bump into.

106
00:04:59,000 --> 00:05:00,800
You can see our layer collision matrix.

107
00:05:00,800 --> 00:05:03,290
So we don't want background to be colliding with anything else.

108
00:05:03,290 --> 00:05:08,120
That should be all we need to do when we x out of that the player is on a separate layer to the background

109
00:05:08,120 --> 00:05:10,940
and the player and the layer aren't bumping into each other.

110
00:05:10,940 --> 00:05:14,210
But we want the player to be able to collide with all the other things.

111
00:05:14,210 --> 00:05:15,020
Let's run, run, run.

112
00:05:15,020 --> 00:05:19,110
We've given Al sign a machine can finer.

113
00:05:19,130 --> 00:05:21,920
Let's just do it so we can see what's actually going on here.

114
00:05:21,950 --> 00:05:24,200
We'll get the game and the scenes side by side.

115
00:05:24,210 --> 00:05:26,300
I know there's not a lot of real estate in my screen now.

116
00:05:26,330 --> 00:05:31,610
We can see on our scene that the camera gets to the end, touches our collision, which outcome Finer

117
00:05:31,610 --> 00:05:33,680
says is the edge of it, doesn't go any further.

118
00:05:33,680 --> 00:05:39,410
And if we go running all the way down to the right, if I can get him down there, still got a couple

119
00:05:39,410 --> 00:05:40,610
of things to fix in the game.

120
00:05:40,610 --> 00:05:45,590
You can see that the camera stops down the end as well and it fails to do the same and to jump up to

121
00:05:45,590 --> 00:05:45,950
the top.

122
00:05:45,950 --> 00:05:47,480
It's going to be confined up at the top.

123
00:05:47,480 --> 00:05:51,380
So this is a really nice way of saying to the player, Hey, ah, you've reached as far as you're allowed

124
00:05:51,380 --> 00:05:57,560
to go because hey, the camera is saying you can't go any further and it's a good design mechanism to

125
00:05:57,560 --> 00:05:59,090
constrain the player within the world.

126
00:05:59,090 --> 00:06:01,010
Looks a little bit garbage down the bottom there.

127
00:06:01,010 --> 00:06:03,920
I think I would need to give my camera a little bit more view of the bottom.

128
00:06:03,920 --> 00:06:05,120
So I'm just going to show you how to do that.

129
00:06:05,120 --> 00:06:10,430
Very briefly, if we click back on our background tile map, jump over to editing, our polite polygon

130
00:06:10,430 --> 00:06:15,440
collider grabbed the point, drag it down and sideways a little bit, drag it up.

131
00:06:15,440 --> 00:06:20,060
Then you can see this is the process really simple and we don't need to do anything else but are being

132
00:06:20,060 --> 00:06:20,270
baited.

133
00:06:20,270 --> 00:06:20,450
Boom.

134
00:06:20,450 --> 00:06:21,920
I'll just finish this very quickly.

135
00:06:22,580 --> 00:06:26,060
We can click on play that will have updated automatically, I think.

136
00:06:26,060 --> 00:06:32,090
I hope, I believe our collision of where the center machine can finer thinks we're allowed to go to

137
00:06:32,090 --> 00:06:33,440
so that is pretty cool.

138
00:06:33,440 --> 00:06:34,070
So happy with that.

139
00:06:34,070 --> 00:06:36,350
We've added some cool functionality to our camera.

140
00:06:36,380 --> 00:06:37,460
I'll see you in the next lecture.

