1
00:00:03,000 --> 00:00:07,170
In this lecture, we're implementing some letters so that we can climb up the ladder and climb down

2
00:00:07,170 --> 00:00:07,710
the ladder.

3
00:00:07,710 --> 00:00:10,350
And I'm going to give this to you as a big old challenge.

4
00:00:10,350 --> 00:00:11,510
So let's get started.

5
00:00:11,520 --> 00:00:16,079
Just a reminder, you've got a piece of the ladder that you downloaded, hopefully when you downloaded

6
00:00:16,079 --> 00:00:17,610
all of this Sprite set.

7
00:00:17,610 --> 00:00:19,380
So you've got the ladder piece in there.

8
00:00:19,380 --> 00:00:22,950
What we're going to do straightaway is take on a mega challenge.

9
00:00:22,950 --> 00:00:26,220
So that being a challenge is going to be to implement ladder climbing.

10
00:00:26,220 --> 00:00:30,690
We've done all the different elements of this, so this will be a good opportunity to bring it all together.

11
00:00:30,690 --> 00:00:33,930
Remember, you need to set up your climbing tile map.

12
00:00:33,930 --> 00:00:35,310
Well, I'm going to call it climbing.

13
00:00:35,310 --> 00:00:36,390
You can call it whatever you want.

14
00:00:36,420 --> 00:00:37,890
You could call it ladder if you wanted.

15
00:00:37,890 --> 00:00:42,270
But just in case we have things other than ladders, say ropes in the future, I'm going to call it

16
00:00:42,270 --> 00:00:44,520
climbing and also the climbing layer.

17
00:00:44,520 --> 00:00:50,190
So we can check to see if we are currently touching something that should allow us to climb to create

18
00:00:50,190 --> 00:00:56,190
the climb ladder method check to see that we're touching the ladder and to apply climb velocity to the

19
00:00:56,190 --> 00:00:59,250
Y axis if we are pushing up or down.

20
00:00:59,250 --> 00:01:01,890
And then in the next lecture we'll be setting the animation.

21
00:01:01,890 --> 00:01:05,459
And there's also an issue where the character slowly slides down the ladder.

22
00:01:05,459 --> 00:01:07,080
So don't worry about those just yet.

23
00:01:07,080 --> 00:01:12,090
We'll do that in the next lecture, but get the base functionality of climbing the ladder set up.

24
00:01:12,120 --> 00:01:13,050
Take on that challenge.

25
00:01:13,050 --> 00:01:14,340
See you back here when you're done.

26
00:01:16,750 --> 00:01:17,590
First step in here.

27
00:01:17,590 --> 00:01:19,870
Let's set up some of our functionality.

28
00:01:19,870 --> 00:01:24,070
I will go over to my tile map grid, right click to the object.

29
00:01:24,070 --> 00:01:28,150
We will find tile map and I'll create another rectangular tile map.

30
00:01:28,150 --> 00:01:31,300
I'll call this the climbing tile map.

31
00:01:31,690 --> 00:01:33,670
Well, here, I'm going to go over to my layers.

32
00:01:33,670 --> 00:01:34,570
We do have ground.

33
00:01:34,570 --> 00:01:37,210
I will add a layer in addition to ground.

34
00:01:37,210 --> 00:01:39,940
Will call this climbing great.

35
00:01:39,940 --> 00:01:41,950
And then back over into the climbing tile map.

36
00:01:41,950 --> 00:01:44,710
And we will change this to be climbing right there.

37
00:01:44,710 --> 00:01:47,680
We should also do our sort order at the same time, shouldn't we?

38
00:01:47,680 --> 00:01:52,570
So I didn't mention that in the list of things to do, but it just popped into my brain just then that

39
00:01:52,570 --> 00:01:53,620
we'll need to have.

40
00:01:53,620 --> 00:02:00,940
Plus, layer five will call climbing, I imagine the climbing layer we'd want to have on top of the

41
00:02:00,940 --> 00:02:02,680
platforms underneath the player.

42
00:02:02,690 --> 00:02:05,080
So the player should definitely be on top of the ladders.

43
00:02:05,080 --> 00:02:07,750
The ladders could be on top of the platforms, I think.

44
00:02:07,750 --> 00:02:10,660
But that's up to you and that should be okay.

45
00:02:10,660 --> 00:02:15,400
Now, within our tile palette, I'm going to grab my ladder and just pop it up in the top there.

46
00:02:15,400 --> 00:02:17,230
It'll ask me where I wish to save that.

47
00:02:17,230 --> 00:02:23,500
We have our assets sprites and you know, I put the rule tile in there because we needed close access

48
00:02:23,500 --> 00:02:25,600
to it, but we don't need that for our ladder.

49
00:02:25,600 --> 00:02:28,300
So I'm going to pop my ladder into the tiles.

50
00:02:28,390 --> 00:02:29,770
We'll call this ladder.

51
00:02:29,770 --> 00:02:30,370
That's fine.

52
00:02:30,370 --> 00:02:31,300
Saved that up.

53
00:02:31,300 --> 00:02:33,970
And now in our palette, we have a letter.

54
00:02:33,970 --> 00:02:36,430
I'm going to click on that and pop one into the scene.

55
00:02:36,430 --> 00:02:37,480
We can't see it.

56
00:02:37,480 --> 00:02:40,210
That means we've done something incorrect in here.

57
00:02:40,390 --> 00:02:42,880
First of all, am I on the right tile map?

58
00:02:42,880 --> 00:02:43,510
Yes, I am.

59
00:02:43,510 --> 00:02:44,470
Am I clicked on the thing?

60
00:02:44,470 --> 00:02:45,520
Yes, I am.

61
00:02:45,610 --> 00:02:46,390
Let's have a look.

62
00:02:46,390 --> 00:02:47,320
What else is going on here?

63
00:02:47,320 --> 00:02:48,990
Click on the climbing tile map.

64
00:02:49,060 --> 00:02:52,930
It could be that we haven't actually said what the sorting layer is.

65
00:02:52,930 --> 00:02:57,600
So under additional settings sorting layer, we need to say that I am climbing bump.

66
00:02:57,640 --> 00:02:58,300
Hey presto.

67
00:02:58,300 --> 00:02:59,110
There we go.

68
00:02:59,140 --> 00:02:59,530
Okay.

69
00:02:59,530 --> 00:03:03,070
I also didn't tell you to do this, but hopefully you've figured it out that you need to play around

70
00:03:03,070 --> 00:03:05,560
a little bit with the collision on the ladder.

71
00:03:05,560 --> 00:03:08,470
So let's have a look at what we've got on our platforms.

72
00:03:08,470 --> 00:03:14,470
We have the tile map, render a tile map and there is a composite collider, 2D that looks like what

73
00:03:14,470 --> 00:03:14,800
we need.

74
00:03:14,800 --> 00:03:21,880
So back over into our climbing, we'll add a composite collider to DX and of course we need to add a

75
00:03:21,880 --> 00:03:24,730
tile map collider to DX to that.

76
00:03:24,730 --> 00:03:28,870
And you can see we have a collider on there now that doesn't look like a very good collider doesn't.

77
00:03:28,870 --> 00:03:35,950
So let's go and edit that if I jump onto my sprite itself, so click on the Sprite and you can see we

78
00:03:35,950 --> 00:03:37,780
have the Sprite editor in here.

79
00:03:37,780 --> 00:03:42,340
We can jump up to Sprite editor and change the custom physics shape.

80
00:03:42,340 --> 00:03:46,840
And within custom physics shape, I'm going to click in the top left drag all the way down to the bottom

81
00:03:46,840 --> 00:03:48,170
right bump.

82
00:03:48,340 --> 00:03:48,760
Okay.

83
00:03:48,760 --> 00:03:50,320
And now we've got a custom shape.

84
00:03:50,320 --> 00:03:54,280
I'll just bring these in a little bit, because sometimes you don't want the player kind of hanging

85
00:03:54,280 --> 00:03:55,870
right on the edge of the ladder.

86
00:03:55,870 --> 00:03:59,410
You want to make sure they've got themselves a little bit in the middle of the ladder.

87
00:03:59,410 --> 00:04:06,100
Now, if I click Apply X out of that, click on my climbing tile map and it may not look right for you.

88
00:04:06,100 --> 00:04:07,240
It might still look the old way.

89
00:04:07,240 --> 00:04:12,730
I had to click and click back on the tile map collider for a to take on that physics shape that we put

90
00:04:12,730 --> 00:04:13,120
on it.

91
00:04:13,120 --> 00:04:13,870
I still don't like.

92
00:04:13,870 --> 00:04:16,000
We've got the little green lines in there.

93
00:04:16,000 --> 00:04:16,750
I'll have a look at that.

94
00:04:16,750 --> 00:04:19,870
If we get stuck on those, then we'll play around with a few things here.

95
00:04:19,899 --> 00:04:23,320
It looks a little bit buggy to me, but we may have done something wrong.

96
00:04:23,320 --> 00:04:25,360
We'll come back to that if need be.

97
00:04:25,360 --> 00:04:31,060
What we need to do next is jump over into our scripts, jump on, play a movement I'm going to find.

98
00:04:31,060 --> 00:04:38,440
I actually create a climb ladder in update, climb ladder, parentheses, semicolon.

99
00:04:38,530 --> 00:04:42,640
I like to have the things in the order they appear run then flips right then climb ladder.

100
00:04:42,670 --> 00:04:46,780
We've got run and then flip sprite and then down the bottom here we'll do our climb ladder.

101
00:04:46,780 --> 00:04:52,150
So void climb ladder parentheses.

102
00:04:52,150 --> 00:04:55,030
Kelly Braces Let's do the movement stuff first.

103
00:04:55,030 --> 00:04:57,760
So we need to give ourselves something very similar to run.

104
00:04:57,760 --> 00:04:58,600
So what do we do and run?

105
00:04:58,600 --> 00:05:03,730
Well, we had a vector two that was all about the lefty righty, and that's the x axis.

106
00:05:03,730 --> 00:05:05,470
And then we applied that to velocity.

107
00:05:05,470 --> 00:05:07,390
So I'm going to copy all of this.

108
00:05:07,390 --> 00:05:08,410
Copy, copy.

109
00:05:08,410 --> 00:05:10,030
Pop this down into climb ladder.

110
00:05:10,030 --> 00:05:11,200
Pasty, pasty.

111
00:05:11,200 --> 00:05:16,420
It's good, I think to once you've understood the concept, it's okay to reuse your code as long as

112
00:05:16,420 --> 00:05:17,230
you know what you're doing.

113
00:05:17,230 --> 00:05:20,620
You don't want to just copy and paste and have a big old guess at things that's not so good.

114
00:05:20,740 --> 00:05:25,360
Instead of player velocity, let's rename this climb velocity.

115
00:05:25,360 --> 00:05:31,390
Actually, I'm going to highlight climb velocity, highlight copy and then change that in the other

116
00:05:31,390 --> 00:05:31,780
spot.

117
00:05:31,780 --> 00:05:32,680
There we go.

118
00:05:32,710 --> 00:05:38,290
So basically we need to flip these around instead of saying keep your existing Y velocity, we're going

119
00:05:38,290 --> 00:05:40,630
to say keep your existing X velocity.

120
00:05:40,630 --> 00:05:41,890
So you know what I'll do?

121
00:05:41,890 --> 00:05:45,850
This is going to look a little bit messy, but I'm going to do it the messy way just so you can see

122
00:05:45,880 --> 00:05:47,020
what's going on here.

123
00:05:47,920 --> 00:05:48,850
Copy that.

124
00:05:48,850 --> 00:05:57,460
Pop it up to this line above new vector to it's one of these things and in here I will delete the first

125
00:05:57,460 --> 00:06:00,760
bit of that delete and I'm just basically using the line below.

126
00:06:00,760 --> 00:06:01,480
I'm doing it this way.

127
00:06:01,480 --> 00:06:04,000
So you can see really clearly what I'm doing on my screen.

128
00:06:04,000 --> 00:06:08,650
My rigid body velocity x is the first part of our equation.

129
00:06:08,650 --> 00:06:10,240
Comma, what do we need next?

130
00:06:10,240 --> 00:06:15,430
Well, we need this move input times by some sort of climb speed, so we will move.

131
00:06:15,590 --> 00:06:17,200
Import export.

132
00:06:17,210 --> 00:06:23,150
This is why this time multiply by we don't have it yet, but we will multiply it by a climb speed.

133
00:06:23,760 --> 00:06:24,300
Okay.

134
00:06:24,350 --> 00:06:26,960
And then I'll delete that just so we've got rid of it.

135
00:06:26,970 --> 00:06:27,560
Quan speed.

136
00:06:27,560 --> 00:06:30,920
We need to create double click copy all the way back up to the top.

137
00:06:30,920 --> 00:06:36,200
We'll find our serialize field serialize field and this will be of type float.

138
00:06:36,200 --> 00:06:41,180
We'll call it climb speed and we'll initialize it at five just because that seems to be a nice number

139
00:06:41,180 --> 00:06:45,710
to initialize all these things at all the way back down again to climb ladder.

140
00:06:45,740 --> 00:06:49,280
We've got our velocity being climb velocity.

141
00:06:49,280 --> 00:06:50,000
Great.

142
00:06:50,000 --> 00:06:54,260
And then the other thing we need to do in here is make sure you're only able to climb if you're touching

143
00:06:54,260 --> 00:06:54,860
the ladder.

144
00:06:54,860 --> 00:06:56,990
So let us create our if statement.

145
00:06:56,990 --> 00:07:00,050
You know, once again, we'll go find what we did in what was it?

146
00:07:00,050 --> 00:07:01,040
It was on jump.

147
00:07:01,040 --> 00:07:06,260
That was if your capsule collider is touching a particular thing so we'll highlight that copy it pop

148
00:07:06,260 --> 00:07:13,880
down to climb ladder if my so if not my capsule collider is touching layers layers mask get mask what

149
00:07:13,880 --> 00:07:15,770
is the mask we're interested in here?

150
00:07:15,770 --> 00:07:18,950
It's going to be climbing with an uppercase C.

151
00:07:18,980 --> 00:07:21,620
How do I know it's climbing back over into unity.

152
00:07:21,620 --> 00:07:23,930
Click on our climbing tile map.

153
00:07:23,930 --> 00:07:27,920
You can see that we've got a sorting layer climbing scroll to the top.

154
00:07:27,920 --> 00:07:29,510
You can see we've got our layer climbing.

155
00:07:29,510 --> 00:07:34,580
If I to click on that, go to the add layer, I could double click on here, copy that to get the exact

156
00:07:34,580 --> 00:07:35,270
naming.

157
00:07:35,270 --> 00:07:36,770
So I know I haven't messed that up.

158
00:07:36,770 --> 00:07:43,130
And then back over into our climb ladder method and we're using climbing as the particular layer we're

159
00:07:43,130 --> 00:07:43,730
interested in.

160
00:07:43,730 --> 00:07:48,590
So this is all just exactly the same as the previous lecture where we're talking about the touching

161
00:07:48,590 --> 00:07:51,380
a particular layer for touching the ground so that we could jump.

162
00:07:51,380 --> 00:07:53,270
If you're not touching that, then return.

163
00:07:53,270 --> 00:07:54,830
Don't do anything further.

164
00:07:54,830 --> 00:07:58,520
If you are touching that, then we're going to do this particular thing.

165
00:07:58,520 --> 00:08:02,330
Let's save that up and see how we're going with our functionality thus far.

166
00:08:02,360 --> 00:08:05,840
Double check that we've got our climbing tile map set up correctly.

167
00:08:05,840 --> 00:08:08,900
It is climbing and it's called layer climbing.

168
00:08:08,930 --> 00:08:10,070
Click on the player.

169
00:08:10,640 --> 00:08:13,220
It's going to be some era somewhere in here, I'm sure.

170
00:08:14,180 --> 00:08:14,930
Run, run, run.

171
00:08:14,930 --> 00:08:16,400
Well, nice.

172
00:08:16,400 --> 00:08:17,750
And we knock over our ladder.

173
00:08:17,750 --> 00:08:19,250
That is, my friends.

174
00:08:19,250 --> 00:08:20,900
Not at all what I was expecting.

175
00:08:20,900 --> 00:08:25,490
The reason that's happened, if we click on the climbing tool map, the rigid body on our ladder, that

176
00:08:25,490 --> 00:08:26,720
was kind of funny.

177
00:08:26,720 --> 00:08:28,220
I totally wasn't expecting that.

178
00:08:28,220 --> 00:08:29,300
We don't want it to be dynamic.

179
00:08:29,300 --> 00:08:33,799
Do we want it to be static so we can't bump into it and knock it over?

180
00:08:33,799 --> 00:08:37,850
I can run out to it, but you know, bump, I'm bumping into it at the moment and that's not what we

181
00:08:37,850 --> 00:08:38,059
want.

182
00:08:38,059 --> 00:08:43,429
I can climb a little bit sort of when I've bumped into it, but we need to resolve this bumpiness.

183
00:08:43,429 --> 00:08:48,170
So if you've got this behavior as well, or if you've just been following with me, just have a think,

184
00:08:48,170 --> 00:08:51,530
pause a video and see what we need to do to stop us bumping into this.

185
00:08:52,720 --> 00:08:53,230
And you know what?

186
00:08:53,230 --> 00:08:57,900
Any time you bump into something that you want to run through, it's usually because we need to make

187
00:08:57,970 --> 00:08:59,170
it a trigger.

188
00:08:59,170 --> 00:09:04,240
A trigger is a type of collision where it doesn't stop the rigid bodies moving.

189
00:09:04,240 --> 00:09:06,310
It doesn't allow us to have that bump into effect.

190
00:09:06,310 --> 00:09:11,530
So we'll make our tunnel map collider and is trigger for our climbing tunnel map.

191
00:09:11,530 --> 00:09:14,950
And when I run over, I can move up and I can move down as well.

192
00:09:14,950 --> 00:09:15,280
Excellent.

193
00:09:15,280 --> 00:09:16,510
So that's exactly what I want.

194
00:09:16,510 --> 00:09:18,090
Can I jump off the ladder?

195
00:09:18,100 --> 00:09:25,030
No, I can't at the moment because we have set up our jumping so that you can only jump when you're

196
00:09:25,030 --> 00:09:26,170
touching the ground layer.

197
00:09:26,170 --> 00:09:27,400
So that's something for us to consider.

198
00:09:27,400 --> 00:09:30,760
Do you want you play to jump off a letter or do you want to say no, no, if you're on a ladder, you

199
00:09:30,760 --> 00:09:32,110
have to float off the ladder.

200
00:09:32,110 --> 00:09:34,960
But for now we've got the functionality that I wanted, which is we can run up.

201
00:09:34,960 --> 00:09:40,120
We can run down only when we're touching a ladder and we've got the drift issue that I was talking about

202
00:09:40,120 --> 00:09:41,530
was slowly floating to the ground.

203
00:09:41,530 --> 00:09:44,830
And also our animation continues to be the idle animation.

204
00:09:44,830 --> 00:09:47,560
So those are things we will work on in the next lecture.

205
00:09:47,590 --> 00:09:49,990
Good stuff and I'll see you in that next lecture.

