1
00:00:03,070 --> 00:00:04,600
In this lecture, we're adding hazards.

2
00:00:04,600 --> 00:00:09,460
So when the player touches the spikes whomp, they trigger the death animation.

3
00:00:09,490 --> 00:00:13,990
Let's go through this process together as setting up our hazards tile map and giving it all the components

4
00:00:13,990 --> 00:00:16,200
and then making sure that we've got things ready to go.

5
00:00:16,210 --> 00:00:22,420
I'm going to give this to you as a series of little Q&A type quiz questions, micro challenges, if

6
00:00:22,420 --> 00:00:22,720
you will.

7
00:00:22,720 --> 00:00:23,500
We'll see how we go.

8
00:00:23,500 --> 00:00:25,450
So the first step, what do we need to do?

9
00:00:25,450 --> 00:00:29,740
First of all, actually to create ourselves a layer to put hazards on.

10
00:00:31,210 --> 00:00:39,010
Well, we need to jump over into toll map grid, right click, find 2D objects, tile map and then rectangular.

11
00:00:39,040 --> 00:00:42,250
We'll call this hazards tile map.

12
00:00:42,400 --> 00:00:43,960
Okay, that's the starting point.

13
00:00:43,990 --> 00:00:48,790
Now, what do we need to do in terms of layers when we create our new tile map?

14
00:00:50,760 --> 00:00:53,160
That's a good chance for you to pause the video and do those things if you want.

15
00:00:53,190 --> 00:00:53,650
That'd be cool.

16
00:00:53,730 --> 00:00:57,970
We can do it together and you can see if you can follow along while doing it the same time.

17
00:00:57,990 --> 00:01:02,730
I'm going to go out to layer on the hazards tile map, click on the default, their add layer and we'll

18
00:01:02,730 --> 00:01:07,340
call this hazards in our user layer 12.

19
00:01:07,350 --> 00:01:10,020
For me, I'm also going to add a sorting layer.

20
00:01:10,050 --> 00:01:11,220
Click on the plus button.

21
00:01:11,940 --> 00:01:13,830
These all call also hazards.

22
00:01:13,830 --> 00:01:18,240
We could probably do it at the same as enemies, but you might want the enemies to run in front or behind

23
00:01:18,270 --> 00:01:18,930
of the hazards.

24
00:01:18,930 --> 00:01:25,110
So we're going to have this zone layer and for now I'll put it in my stack here it'll be layer five,

25
00:01:25,110 --> 00:01:28,860
which is just above enemies, meaning enemies will run in front of the hazards.

26
00:01:29,610 --> 00:01:30,120
Okay.

27
00:01:30,120 --> 00:01:33,210
So next, what do we do with these layers now that we've made them?

28
00:01:33,210 --> 00:01:35,070
Where do we need to go and set them?

29
00:01:36,530 --> 00:01:38,420
Well over into hazard's tile map.

30
00:01:38,420 --> 00:01:44,090
I'll change the layer to be hazards and then we'll find our time map renderer and we'll change the sorting

31
00:01:44,090 --> 00:01:46,640
layer to hazards as well.

32
00:01:46,670 --> 00:01:47,030
Okay.

33
00:01:47,060 --> 00:01:48,500
Doing well so far.

34
00:01:48,530 --> 00:01:53,420
Next up, go and find the spikes that I gave you way back when you got these assets.

35
00:01:53,450 --> 00:01:55,540
These are some more some pretty bad, Rick.

36
00:01:55,550 --> 00:01:59,640
Art, if you think you can do better, then by all means create some nicer spikes.

37
00:01:59,660 --> 00:02:03,470
If you're not sure how, then you can jump into our pixel art course and learn a few things there.

38
00:02:03,500 --> 00:02:08,210
I'm going to click on the Sprite editor because I need to make sure that the physics shape is suitable.

39
00:02:08,210 --> 00:02:12,260
So I'll click on the Sprite editor, top left custom physics shape.

40
00:02:12,260 --> 00:02:14,780
I'm going to drag loosely around my object.

41
00:02:14,780 --> 00:02:16,040
You might want to drag in the middle.

42
00:02:16,040 --> 00:02:18,650
I found if you drag off the screen, it doesn't work.

43
00:02:18,650 --> 00:02:21,710
So drag somewhere in the middle yet four points bottom left.

44
00:02:23,200 --> 00:02:23,530
Bottom.

45
00:02:23,530 --> 00:02:27,100
Right, and I'll just put this up at the top here a little bit.

46
00:02:27,550 --> 00:02:30,010
Now, just right, touching the spikes, I think that's fine.

47
00:02:30,010 --> 00:02:31,660
Doesn't matter if there's not a gap in the middle.

48
00:02:31,660 --> 00:02:33,340
We don't need to follow the contour of these.

49
00:02:33,340 --> 00:02:37,480
Exactly, because the player is going to generally jump on top of these, even though there's two.

50
00:02:37,480 --> 00:02:40,540
And anything that matters, click on apply that should be good.

51
00:02:41,430 --> 00:02:42,210
Ex out of that.

52
00:02:42,210 --> 00:02:48,540
Now what else do we need to do on our hazards tile map to make sure that we can collide with our spikes.

53
00:02:49,620 --> 00:02:56,850
We need to go to add component and we'll add a tile map collider to DD so then it knows anything we

54
00:02:56,850 --> 00:02:59,460
put in there should have collision on it, which is great.

55
00:03:00,160 --> 00:03:05,330
Now you know what I'll do now is I'll just dig out a couple of holes to put our spikes in.

56
00:03:05,340 --> 00:03:08,480
So for me, I'm going to go to my platform's tile map.

57
00:03:08,490 --> 00:03:13,080
I'll click on my rule tile, give myself a little extra ledge here to jump up there.

58
00:03:13,080 --> 00:03:15,750
I'm going to hold down shift to delete some spots.

59
00:03:15,750 --> 00:03:20,610
So that's how you can delete delete some spots in there that I can put some spikes in maybe a couple

60
00:03:20,610 --> 00:03:21,720
of spots up here as well.

61
00:03:21,720 --> 00:03:25,440
You know, we'll make this a big, old, big old pit with spikes down the bottom of it.

62
00:03:25,440 --> 00:03:26,620
That looks pretty good.

63
00:03:26,640 --> 00:03:31,080
Next up, we need to be able to paint the spikes on to our hazards tile map.

64
00:03:31,080 --> 00:03:32,400
So what do we need to do there?

65
00:03:32,400 --> 00:03:33,930
How do we go about doing that?

66
00:03:34,670 --> 00:03:36,280
Well, hopefully you're following along.

67
00:03:36,290 --> 00:03:38,800
You're yelling at the screen or you're actually just doing this.

68
00:03:38,810 --> 00:03:43,840
I'm going to drag the spikes into my palette and then I'll ask me where we want to save it.

69
00:03:43,850 --> 00:03:44,500
Assets.

70
00:03:44,510 --> 00:03:46,220
We will save these in.

71
00:03:46,220 --> 00:03:47,400
Let's see.

72
00:03:47,420 --> 00:03:50,270
Tiles I think is good and just called spikes.

73
00:03:50,270 --> 00:03:51,110
Excellent save.

74
00:03:51,110 --> 00:03:52,520
You can see we've got spikes down here.

75
00:03:52,520 --> 00:03:58,610
Now if I change my active tile map, very important to hazards, click on the spikes and I can paint

76
00:03:58,610 --> 00:03:59,870
those in the spots.

77
00:03:59,870 --> 00:04:04,550
And the good thing is I can see the green collision around it knowing that I should be able to bump

78
00:04:04,550 --> 00:04:05,810
into those, collide with them.

79
00:04:05,810 --> 00:04:07,250
I've got a couple of spikes in there.

80
00:04:07,250 --> 00:04:08,540
I'm happy with those.

81
00:04:08,630 --> 00:04:10,790
Now there's one more main step we need to do in here.

82
00:04:10,790 --> 00:04:14,900
We need to say in our code that the player can collide with this particular layer.

83
00:04:14,900 --> 00:04:17,360
So how do we go about doing that?

84
00:04:18,529 --> 00:04:23,570
I'm going to click on hazards, go to my add layer and just double click on hazards and copy that to

85
00:04:23,570 --> 00:04:25,610
make sure I get the spelling exact.

86
00:04:25,610 --> 00:04:29,300
Because this is hitting me a couple of times that I've got it not exact and haven't figured out what

87
00:04:29,300 --> 00:04:29,990
was going on.

88
00:04:29,990 --> 00:04:32,780
Find my scripts, jump into the player movement script.

89
00:04:32,810 --> 00:04:38,630
Now if we scroll down to die, we can see that we've got our collider touching layers, we're touching

90
00:04:38,630 --> 00:04:38,960
enemy.

91
00:04:38,960 --> 00:04:43,580
We can also comma quotation marks and paste in hazards in there.

92
00:04:43,580 --> 00:04:48,110
So if we're touching enemies or hazards, we should to all of our dying related things.

93
00:04:48,110 --> 00:04:50,060
So save back over into unity.

94
00:04:50,060 --> 00:04:51,530
Let's see if this is working.

95
00:04:51,770 --> 00:04:52,760
Click on play.

96
00:04:54,340 --> 00:04:55,480
Run and run and jump.

97
00:04:55,480 --> 00:04:56,680
And we're not dying now.

98
00:04:56,680 --> 00:04:58,570
I think I know what's going on here.

99
00:04:58,570 --> 00:05:02,280
And it's something that I identified a little bit of a bug just a moment ago.

100
00:05:02,290 --> 00:05:07,870
If you have a look at our player and our spikes, we're not getting to the point where we can actually

101
00:05:07,870 --> 00:05:12,760
get our capsule collider to touch the spikes because our feet are preventing it.

102
00:05:12,760 --> 00:05:18,250
That's because our feet is a collider, not a trigger, and the spikes are a collider, not a trigger.

103
00:05:18,250 --> 00:05:23,800
So we're not falling through these to get to the point because our we want to have our feet on the very,

104
00:05:23,800 --> 00:05:24,940
very bottom of things.

105
00:05:24,940 --> 00:05:28,840
So the way to resolve this is we can just make our hazards colliders.

106
00:05:28,840 --> 00:05:34,660
And so if we click on our hazard tile map and change that to let's see the tunnel map collider change

107
00:05:34,660 --> 00:05:35,830
it to is trigger.

108
00:05:35,860 --> 00:05:41,440
Now if we click on play, that means we should fall through it and we can actually touch our collider

109
00:05:41,440 --> 00:05:41,740
to it.

110
00:05:41,740 --> 00:05:43,060
Boink and then we go, we die.

111
00:05:43,090 --> 00:05:45,460
Let's have a look and see what the behavior is with the enemy.

112
00:05:45,460 --> 00:05:51,580
So I have a suspicion the enemy has its collider or that that is going to prevent us actually getting

113
00:05:51,580 --> 00:05:52,720
to our collider as well.

114
00:05:52,720 --> 00:05:55,420
So I think I didn't test this in the last lecture.

115
00:05:55,420 --> 00:05:56,380
Apologies for that.

116
00:05:56,380 --> 00:06:00,580
I think if we jump on the top of our enemy, we're not going to die straight away, okay?

117
00:06:00,580 --> 00:06:02,650
And then we die when it finally touches our capsule.

118
00:06:02,650 --> 00:06:04,030
Collider So same thing again.

119
00:06:04,030 --> 00:06:07,870
I'll click on the enemy and I'll change the enemy's capsule.

120
00:06:07,870 --> 00:06:11,410
Collider To be a trigger so that our feet can fall through it.

121
00:06:11,410 --> 00:06:14,980
I don't think there's going to be anything else that is going to be affected.

122
00:06:15,130 --> 00:06:18,430
It's fine if the enemy is a trigger, we're going to do have things trigger.

123
00:06:18,430 --> 00:06:22,030
So let's see with that, I think I might have a little bit of a bug with it turning.

124
00:06:22,240 --> 00:06:22,700
Not probably.

125
00:06:22,700 --> 00:06:23,140
Yeah, I will.

126
00:06:23,140 --> 00:06:24,580
But let's just see if we can land on it.

127
00:06:24,580 --> 00:06:26,740
First point, we land on it, we die straight away.

128
00:06:26,740 --> 00:06:27,730
So that part's fixed.

129
00:06:27,730 --> 00:06:28,930
Why are we doing the jiggly?

130
00:06:28,930 --> 00:06:29,320
Jiggly?

131
00:06:29,320 --> 00:06:31,210
Well, I think I know what's going on here.

132
00:06:31,210 --> 00:06:32,860
I'm going to show you a little technique.

133
00:06:32,860 --> 00:06:35,410
If you click on play, get ready on the pause.

134
00:06:35,410 --> 00:06:37,090
Just before we get to the end.

135
00:06:37,090 --> 00:06:40,480
I've clicked pause and you can step through, step through, step through.

136
00:06:40,510 --> 00:06:44,110
You can see that the reverse periscope is going through it.

137
00:06:44,740 --> 00:06:46,360
It exits the collision.

138
00:06:46,360 --> 00:06:47,140
We flip.

139
00:06:47,140 --> 00:06:53,260
But now this that we've made a trigger is touching is inside this collision.

140
00:06:53,260 --> 00:06:54,460
So I just flipped and that's in there.

141
00:06:54,460 --> 00:06:58,120
But then once it exits, it flips back again.

142
00:06:58,120 --> 00:07:02,500
So we just need to deliver of spacing, which should be okay, I'm going to get the reverse periscope

143
00:07:02,500 --> 00:07:05,410
and click on Let's See the Box Collide.

144
00:07:05,410 --> 00:07:07,600
I click on edit, just move that out a little bit further.

145
00:07:07,600 --> 00:07:13,510
So it's going to turn a little bit sooner just to there should be good and we'll move the capsule.

146
00:07:13,510 --> 00:07:16,930
Collider So it's just a little bit less spacious around the outside.

147
00:07:16,930 --> 00:07:18,670
It doesn't need to be quite so high either.

148
00:07:18,670 --> 00:07:21,670
So I'll put the collider in a bunch here and all.

149
00:07:21,670 --> 00:07:26,110
We could move the periscope out a little bit more and the enemy flips around because the periscope is

150
00:07:26,110 --> 00:07:27,370
doing what it's supposed to be doing.

151
00:07:28,000 --> 00:07:31,510
Let's see if we can now jump onto the spikes we can forward.

152
00:07:31,510 --> 00:07:32,050
It flings us.

153
00:07:32,050 --> 00:07:33,520
Good, good reaction there.

154
00:07:33,550 --> 00:07:38,500
We'll see if we can hit the enemy and if it causes our death animation, then we're all good.

155
00:07:38,500 --> 00:07:39,280
Jump on top of it.

156
00:07:39,280 --> 00:07:39,730
Great.

157
00:07:39,730 --> 00:07:40,330
So there we go.

158
00:07:40,330 --> 00:07:42,490
We've got our hazards and we've got our player.

159
00:07:42,490 --> 00:07:46,840
Oh, you know, one last thing I'll show you is the fact that anything we put on this hazardous tile

160
00:07:46,870 --> 00:07:49,780
map becomes a hazard that will harm the player.

161
00:07:49,780 --> 00:07:54,310
So say all this water up here, instead of the water being on the water tile map, it's going to click

162
00:07:54,310 --> 00:07:59,080
on the water tile map and I'm going to find my tile palette, click on the water, I'll click on anything,

163
00:07:59,080 --> 00:08:00,340
hold down, shift and delete.

164
00:08:00,340 --> 00:08:01,330
That's just an easier way.

165
00:08:01,330 --> 00:08:02,800
Deleting then getting the eraser.

166
00:08:02,830 --> 00:08:05,320
Now I'm going to click back on the hazards.

167
00:08:05,320 --> 00:08:07,630
Tile map has its tile map just here.

168
00:08:07,660 --> 00:08:08,980
I'm going to click on water.

169
00:08:08,980 --> 00:08:12,430
I'm going to add the water into the hazards tile map.

170
00:08:12,430 --> 00:08:17,230
Now, when I jump over and touch the water, that should cause some sort of death reaction as well because

171
00:08:17,230 --> 00:08:18,730
it's now considered a hazard.

172
00:08:19,060 --> 00:08:22,210
Okay, that's getting funny as opposed to considered water.

173
00:08:22,210 --> 00:08:26,170
So it's up to you whether you want the water to be a hazard or whether you want the water to be something

174
00:08:26,170 --> 00:08:30,430
you can walk through or maybe even swim through if you want to play around with that functionality for

175
00:08:30,430 --> 00:08:32,049
now, I'm going to leave it as a hazard.

176
00:08:32,380 --> 00:08:35,440
That means the water tile map doesn't have anything on it for the moment, but that's okay.

177
00:08:35,440 --> 00:08:36,970
We might do something with that later on.

178
00:08:36,970 --> 00:08:38,620
I'm going to have it on the hazard.

179
00:08:38,620 --> 00:08:42,580
So the challenge I've got for you is to play some hazards in your level if you haven't done so already,

180
00:08:42,580 --> 00:08:45,550
experiment with different objects, place some hazards in your level.

181
00:08:45,550 --> 00:08:48,790
You can have some water, you can have some spikes, you can create your own things, be a little bit

182
00:08:48,790 --> 00:08:51,820
creative, and when you've added some hazards, you're ready for the next lecture.

183
00:08:51,820 --> 00:08:53,620
So I will see you in that next lecture.

