1
00:00:03,030 --> 00:00:07,530
In this lecture, we're going to wrap up the main functionality for this section of the course by adding

2
00:00:07,530 --> 00:00:08,370
in a boost.

3
00:00:08,370 --> 00:00:13,650
When I drive over this yellow thing, I go a little bit quicker and then when I bump into anything else,

4
00:00:13,650 --> 00:00:15,780
I go slower than I was going before.

5
00:00:15,780 --> 00:00:19,670
So let's implement our speed up and our slow down mechanism.

6
00:00:19,680 --> 00:00:23,640
I'm going to give you a couple of starting pieces for this and then give you a pretty meaty challenge

7
00:00:23,640 --> 00:00:24,750
to sink your teeth into.

8
00:00:24,750 --> 00:00:30,450
So first thing I do in the hierarchy is right click to the object and I'll create a sprite, which will

9
00:00:30,450 --> 00:00:36,690
be a Oh, make this a circle, I think just to make it look a little bit different and I'll call this

10
00:00:36,690 --> 00:00:38,130
a speed up.

11
00:00:38,280 --> 00:00:39,870
Now, where's the speed up in my scene?

12
00:00:39,870 --> 00:00:40,380
Double click.

13
00:00:40,380 --> 00:00:41,310
It'll take me right to it.

14
00:00:41,310 --> 00:00:46,200
It's underneath a tree because that where was that was the middle of the camera when I added this into

15
00:00:46,200 --> 00:00:46,860
the scene.

16
00:00:46,860 --> 00:00:49,680
I want to hit w move this over to the left.

17
00:00:49,680 --> 00:00:53,850
I think it's under my road, so I need to put it up, say five in the order.

18
00:00:53,850 --> 00:00:54,690
Change the color.

19
00:00:54,690 --> 00:00:57,180
I think yellowy orange kind of thing makes sense.

20
00:00:57,180 --> 00:00:58,110
Maybe a yellow.

21
00:00:58,110 --> 00:00:59,700
And so I don't have to drive too far.

22
00:00:59,700 --> 00:01:00,270
I'll be lazy.

23
00:01:00,270 --> 00:01:03,030
I'll put it right over near where my car is at the moment.

24
00:01:03,030 --> 00:01:03,600
So there we go.

25
00:01:03,600 --> 00:01:08,010
Probably make it just a tiny bit bigger, hitting R and scaling it up a little bit.

26
00:01:08,010 --> 00:01:08,340
There we go.

27
00:01:08,340 --> 00:01:13,200
That's a speed up thingy that when I drive over it, I wished to speed up.

28
00:01:13,200 --> 00:01:14,970
Now I'm going to open up my driver script.

29
00:01:14,970 --> 00:01:20,820
Everything we do can be done in driver in this case, and I'm going to give myself two more serialized

30
00:01:20,820 --> 00:01:21,870
fields up at the top here.

31
00:01:21,870 --> 00:01:26,340
So Serialize Field will get a float and I'll call this slow speed.

32
00:01:26,370 --> 00:01:29,520
It's going to represent how slow we go when we bump into something.

33
00:01:29,520 --> 00:01:33,420
I'll initialize that at 0.1 F just the same as move speed.

34
00:01:33,420 --> 00:01:36,090
At the moment, I don't know what it actually is in the game.

35
00:01:36,090 --> 00:01:41,700
If I click on Cruising MC Drive, we've probably modified this in the inspector, so it's currently

36
00:01:41,730 --> 00:01:42,180
hidden.

37
00:01:42,180 --> 00:01:45,090
We open that up and currently the move speed is 20.

38
00:01:45,090 --> 00:01:48,000
Okay, so my initialization is way off in there.

39
00:01:48,000 --> 00:01:52,500
Will make this 24 slow speed and I'll just while I'm here, this won't change anything.

40
00:01:52,500 --> 00:01:56,280
But just in case we do some updates for our code, I'm just going to make that 20.

41
00:01:56,490 --> 00:01:56,970
And you know what?

42
00:01:56,970 --> 00:02:00,960
Slow speed will make 15 a little bit slower than the regular old move speed.

43
00:02:00,960 --> 00:02:05,700
Now I'm going to add a next serialised field and this will be of type float and we'll call this boost

44
00:02:05,700 --> 00:02:06,660
speed.

45
00:02:06,660 --> 00:02:07,590
How much do we want?

46
00:02:07,590 --> 00:02:10,259
Boost B will say 30 F as a starting point.

47
00:02:10,259 --> 00:02:12,030
So we've got this concept now, these variables.

48
00:02:12,030 --> 00:02:13,320
One is our general old.

49
00:02:13,320 --> 00:02:17,400
Here's how fast we're going to be moving and we're using that throughout our code just down in here.

50
00:02:17,400 --> 00:02:22,560
And the other is how slow we're going to go or how fast we're going to go and save that up.

51
00:02:22,560 --> 00:02:26,220
And with that done, I'm going to give you a big challenge.

52
00:02:26,220 --> 00:02:30,840
That big a challenge is going to be to create a boost and bump system.

53
00:02:30,840 --> 00:02:32,730
So boosts are triggers.

54
00:02:32,730 --> 00:02:34,650
We've just put one of these into our scene.

55
00:02:34,650 --> 00:02:38,670
If you look at this thing here, this is what I mean by this boost thing.

56
00:02:38,670 --> 00:02:39,960
It's going to be a trigger.

57
00:02:39,960 --> 00:02:41,640
So some things you need to do to that.

58
00:02:41,640 --> 00:02:43,350
But I want that to speed up the player.

59
00:02:43,350 --> 00:02:47,370
When we drive over it, we're going to have bumps and bumps are going to be colliders, which slow down

60
00:02:47,370 --> 00:02:47,880
the player.

61
00:02:47,880 --> 00:02:52,620
I'm pretty much going to make everything else in my world, all these other things, houses and trees

62
00:02:52,620 --> 00:02:53,130
and stuff.

63
00:02:53,130 --> 00:02:55,380
If I bump into them, I'm going to slow my vehicle down.

64
00:02:55,380 --> 00:02:56,280
That'll be my approach.

65
00:02:56,280 --> 00:03:01,050
With that, you could make separate things that you bump into, which slow the player down if you wanted

66
00:03:01,050 --> 00:03:03,660
to like witches, hats or cones that you place around.

67
00:03:03,840 --> 00:03:06,150
And we can do all of this in our driver script.

68
00:03:06,150 --> 00:03:09,510
So there's other ways you could do this in the future, but for now, we're just going to do it all

69
00:03:09,510 --> 00:03:09,600
in.

70
00:03:09,600 --> 00:03:12,000
Driver You might want to use a tag.

71
00:03:12,000 --> 00:03:17,760
And the other little hint I'll give you here is remember our on events so on trigger enter for example,

72
00:03:17,760 --> 00:03:21,330
we might want to be playing around with those sorts of things and essentially what we're doing is changing

73
00:03:21,330 --> 00:03:27,480
move speed to be either slow speed or boost speed depending upon what happens, depending upon whether

74
00:03:27,480 --> 00:03:30,060
we trigger something or bump into something.

75
00:03:30,060 --> 00:03:32,940
We want to be changing what the value of move speed is.

76
00:03:32,940 --> 00:03:33,600
So there we go.

77
00:03:33,600 --> 00:03:37,440
It's a little bit of a trickier challenge, so be sure to give it a shot.

78
00:03:37,440 --> 00:03:40,800
This is how you learn by sitting there and staring at it and trying to figure it out.

79
00:03:40,800 --> 00:03:45,900
But if you get really stuck, then you're more than welcome to watch my approach, which I'll go through

80
00:03:46,140 --> 00:03:49,020
after you come back from giving it your best shot.

81
00:03:49,020 --> 00:03:52,560
So pause a video and I'll see you back here when you've given a good old try.

82
00:03:55,990 --> 00:03:56,610
Rightio.

83
00:03:56,620 --> 00:04:02,200
So I need to in my driver script, I need to get rid of Start because we're not actually using that

84
00:04:02,200 --> 00:04:02,830
at all are we.

85
00:04:02,830 --> 00:04:04,060
Start don't need you.

86
00:04:04,060 --> 00:04:09,820
What we do need to have in here is some on events so on trigger into remember the two.

87
00:04:09,820 --> 00:04:12,250
RD So you're not crazy like Rick for getting the two?

88
00:04:12,250 --> 00:04:17,769
RD I can just hit tab that will auto complete remove the private because I tend not to like it and then

89
00:04:17,769 --> 00:04:19,870
give myself a little bit of extra formatting in here.

90
00:04:19,870 --> 00:04:21,370
What are we going to be doing without triggering?

91
00:04:21,370 --> 00:04:23,170
Well, it's really similar to the delivery.

92
00:04:23,170 --> 00:04:29,290
So if we jump over to our delivery script and scroll down, you can see that we've got if the tag relates

93
00:04:29,290 --> 00:04:30,940
to something, then we do some things.

94
00:04:30,940 --> 00:04:33,120
So let's put an if statement in our driver dot.

95
00:04:33,280 --> 00:04:40,540
So if tag equals equals and I haven't created this yet, but we'll put in parentheses and then boost.

96
00:04:40,540 --> 00:04:41,830
So we need to create that in a moment.

97
00:04:41,830 --> 00:04:44,860
So if it equals boost, then curly braces.

98
00:04:44,860 --> 00:04:54,040
Let's just for now debug dot log and we'll say are you are boosting man okay just to make sure that

99
00:04:54,040 --> 00:04:58,450
it works before we do any more of our logic, save that up, hop back over into unity.

100
00:04:58,450 --> 00:05:03,730
And I need to make sure that when I run over this guy here, it's got all the things it needs on it.

101
00:05:03,730 --> 00:05:04,690
So what does it need?

102
00:05:04,690 --> 00:05:08,200
Well, it needs to have a collider for a start.

103
00:05:08,200 --> 00:05:11,620
So we'll choose a circle collider to RD.

104
00:05:11,650 --> 00:05:14,560
We need to make that a trigger very important.

105
00:05:14,560 --> 00:05:18,520
We don't need to put on a rigid body because we don't want to be bouncing it around.

106
00:05:18,520 --> 00:05:21,400
It's just going to stay there where it is and we also need it to be tagged.

107
00:05:21,400 --> 00:05:26,830
So I'm going to add a new tag, which I will click the little plus button and call this boost with a

108
00:05:26,830 --> 00:05:29,080
capital B, click on Save.

109
00:05:29,080 --> 00:05:35,860
Now I need to click back on my speed up again and I will change the tag to B Boost.

110
00:05:35,860 --> 00:05:37,000
Now we'll see if that works.

111
00:05:37,000 --> 00:05:44,080
When I click on play, I can drive, drive, drive and we should print out the console something down

112
00:05:44,080 --> 00:05:44,890
here, which we didn't.

113
00:05:44,890 --> 00:05:46,450
So once again, Rick's made a mistake.

114
00:05:46,450 --> 00:05:48,790
Let's see what we've done here on trigger into two 2D.

115
00:05:48,790 --> 00:05:49,300
Yes.

116
00:05:49,300 --> 00:05:49,630
Okay.

117
00:05:49,630 --> 00:05:53,530
So the mistake I made sorry I was going through this a little bit too quickly and not paying attention.

118
00:05:53,530 --> 00:05:55,510
It's not tag equals boost, is it?

119
00:05:55,510 --> 00:05:58,960
If we go back to delivery wins, says other tag, why is it other?

120
00:05:58,960 --> 00:06:03,040
Well, when we collide with something, we're getting this information passed in.

121
00:06:03,040 --> 00:06:06,790
And don't worry if you don't understand passing in and parameters and stuff yet, we'll do that a lot

122
00:06:06,790 --> 00:06:08,170
more throughout this course.

123
00:06:08,170 --> 00:06:11,950
But for now we just need to know we're getting information about others, so it needs to be other dot

124
00:06:12,010 --> 00:06:13,060
tag.

125
00:06:13,120 --> 00:06:13,690
Okay.

126
00:06:13,690 --> 00:06:14,170
And you know what?

127
00:06:14,170 --> 00:06:16,870
A lot of my mistakes, I make a few, I edit them out.

128
00:06:16,870 --> 00:06:18,400
But every now and again I like to keep them in.

129
00:06:18,400 --> 00:06:23,740
Just so you can see the thought process I'm going through if errors come up because I guarantee there's

130
00:06:23,740 --> 00:06:24,850
going to be issues and errors.

131
00:06:24,850 --> 00:06:28,600
Even if you're following along with what I'm doing, you're going to type something a little bit wrong

132
00:06:28,600 --> 00:06:29,110
or miss it.

133
00:06:29,110 --> 00:06:30,550
So it's good to know that process.

134
00:06:30,550 --> 00:06:34,030
Also good to know that folks like myself do that as well.

135
00:06:34,420 --> 00:06:38,320
Okay, so when I drive over this oak, you are boosting, man.

136
00:06:38,320 --> 00:06:38,920
Perfect.

137
00:06:38,920 --> 00:06:39,280
Okay.

138
00:06:39,280 --> 00:06:40,930
What does it mean to boost?

139
00:06:40,930 --> 00:06:42,790
Well, sort of debugging that.

140
00:06:42,790 --> 00:06:43,630
We don't need that anymore.

141
00:06:43,660 --> 00:06:48,190
As cool as it was, we want to be changing our speed.

142
00:06:48,190 --> 00:06:52,300
So currently we have move speed equals something and we're using move speed in here.

143
00:06:52,300 --> 00:06:53,560
So we run over the boost.

144
00:06:53,560 --> 00:06:58,210
When I say move, speed equals boost speed.

145
00:06:58,390 --> 00:06:58,870
Okay.

146
00:06:58,870 --> 00:07:03,430
So basically whatever is stored in boost speed is going to be shoved in to move speed.

147
00:07:03,430 --> 00:07:10,360
So if we're currently storing 30, that will be what is shoved into or assigned into move speed.

148
00:07:10,360 --> 00:07:12,520
So let's save back to unity.

149
00:07:12,700 --> 00:07:14,440
We'll see if that actually worked.

150
00:07:14,440 --> 00:07:15,490
Click on play.

151
00:07:15,490 --> 00:07:20,860
Sometimes it's good to test these things with a really huge value because let's see, do I feel like

152
00:07:20,860 --> 00:07:21,760
I'm going faster?

153
00:07:21,760 --> 00:07:24,070
Yes, I felt like I was going a little bit faster.

154
00:07:24,070 --> 00:07:27,370
And it's going to stay that speed now because I haven't done anything to stop it going that quick.

155
00:07:27,370 --> 00:07:29,860
But that certainly feels like it's going 30.

156
00:07:29,890 --> 00:07:32,320
How can we tell if I click on Cruise in my drive?

157
00:07:32,350 --> 00:07:33,580
There's probably Move Speed somewhere.

158
00:07:33,580 --> 00:07:34,270
Yeah, move.

159
00:07:34,270 --> 00:07:37,060
Speed is now at 30, the same as boost speed.

160
00:07:37,060 --> 00:07:39,220
If I click play then move.

161
00:07:39,220 --> 00:07:41,350
Speed will return back to the 20 that it was excellent.

162
00:07:41,350 --> 00:07:46,060
So we have created ourselves to speed up, but we want to make sure that we stop speeding up if we bump

163
00:07:46,060 --> 00:07:47,980
into something like a crazy person.

164
00:07:47,980 --> 00:07:54,280
So that's the other thing I'm going to do in here is going to be on collision, enter to DX, get rid

165
00:07:54,280 --> 00:07:57,610
of private and just do a little bit of reformatting here.

166
00:07:57,640 --> 00:07:59,830
My particular style, you don't need to follow it.

167
00:07:59,860 --> 00:08:03,520
Okay, hit tab and then I'm going to what what I want to do in here.

168
00:08:03,520 --> 00:08:09,460
Well, if I bump into something, it's just a simple case of saying move speed equals slow speed.

169
00:08:09,880 --> 00:08:13,840
So we're going to assign the value of slow speed to become the value of move speed.

170
00:08:13,840 --> 00:08:14,500
Save that.

171
00:08:14,500 --> 00:08:17,080
And this is if we bump into anything at all.

172
00:08:17,080 --> 00:08:21,190
So if you want to have it a little bit more specific, then you would need to use some tags or need

173
00:08:21,190 --> 00:08:22,570
to use some other ways of doing that.

174
00:08:22,570 --> 00:08:26,680
But I'm just going to say, if you're crazy enough to bump into anything, then you deserve to go a

175
00:08:26,680 --> 00:08:31,000
little bit slower, click on play and make my windows a little bit bigger, I think.

176
00:08:31,630 --> 00:08:37,030
Okay, did the dirt get a little bit of a run up here, bump into that loop and then bump into that?

177
00:08:37,030 --> 00:08:38,409
You can see there's definitely a difference.

178
00:08:38,409 --> 00:08:41,770
Now I'm going slow and bumping into everything.

179
00:08:41,770 --> 00:08:42,429
Now I'm going fast.

180
00:08:42,460 --> 00:08:43,150
Now going slow.

181
00:08:43,150 --> 00:08:43,600
Oh yeah, cool.

182
00:08:43,600 --> 00:08:44,650
So it's definitely working.

183
00:08:44,650 --> 00:08:50,260
We've got a way that we can go faster when we hit a speedy thing and we've got a way that we can go

184
00:08:50,260 --> 00:08:54,280
slower when we bump into any sort of collision and slow our vehicle.

185
00:08:54,340 --> 00:08:54,910
Down again.

186
00:08:54,910 --> 00:08:58,450
And also, you can see I'm green at the moment, so our package stuff still working.

187
00:08:58,450 --> 00:09:01,840
And you can also see that I'm pretty bad at driving in my own game.

188
00:09:01,840 --> 00:09:04,960
Okay, so that's the core functionality I wanted to implement in my game.

189
00:09:04,960 --> 00:09:09,910
We can drive around a car, we can pick up packages, we can deliver the packages, we can change the

190
00:09:09,910 --> 00:09:12,520
colour to give visual feedback, the packages disappear.

191
00:09:12,520 --> 00:09:14,380
We can bump into things without collision.

192
00:09:14,380 --> 00:09:18,040
We can trigger things to go quicker, we can bump into things to go slower.

193
00:09:18,040 --> 00:09:22,450
And all in all, we've got a fun little game that you could build upon and take in a whole bunch of

194
00:09:22,450 --> 00:09:23,350
different directions.

195
00:09:23,350 --> 00:09:26,800
So that's all of the main content I wanted to cover in this section.

196
00:09:26,800 --> 00:09:27,670
Great work.

197
00:09:27,670 --> 00:09:29,290
I look forward to seeing what you've created.

198
00:09:29,290 --> 00:09:32,920
Please do share with us what you've got and I'll see you in the next lecture.

