WEBVTT

1
00:00:08.140 --> 00:00:09.839 A:middle L:90%
Okay, so welcome back, we're going to be

2
00:00:09.839 --> 00:00:12.550 A:middle L:90%
setting up some mesh colliders on the terrain right now

3
00:00:12.550 --> 00:00:14.699 A:middle L:90%
just because we want to make sure that the character

4
00:00:14.699 --> 00:00:16.469 A:middle L:90%
doesn't fall through the world. It's always a good

5
00:00:16.469 --> 00:00:19.920 A:middle L:90%
thing. So just select all of the mesh items,

6
00:00:19.929 --> 00:00:23.350 A:middle L:90%
add component type in mesh collider and then you'll

7
00:00:23.350 --> 00:00:25.160 A:middle L:90%
see that each one of the meshes has its own

8
00:00:25.170 --> 00:00:27.379 A:middle L:90%
has itself is a mesh collider. You also want

9
00:00:27.379 --> 00:00:28.679 A:middle L:90%
to set a rigid body on all these. So

10
00:00:28.679 --> 00:00:30.719 A:middle L:90%
the physics calculations work. So this type of rigid

11
00:00:30.719 --> 00:00:32.909 A:middle L:90%
body, add it. I like to make this mass

12
00:00:32.909 --> 00:00:35.380 A:middle L:90%
really huge. All that doesn't matter. Um Turn

13
00:00:35.380 --> 00:00:38.100 A:middle L:90%
off gravity which means it won't follow the floor or

14
00:00:38.100 --> 00:00:40.429 A:middle L:90%
like fall into oblivion. Uh you want to make

15
00:00:40.429 --> 00:00:42.509 A:middle L:90%
sure that it is kinematic so it doesn't move.

16
00:00:42.520 --> 00:00:45.210 A:middle L:90%
And you also want to make sure that the character

17
00:00:45.210 --> 00:00:46.829 A:middle L:90%
has a rigid body as well. So we're gonna

18
00:00:46.829 --> 00:00:49.259 A:middle L:90%
add a component to him at a rigid body.

19
00:00:49.640 --> 00:00:53.600 A:middle L:90%
We also had a capsule collider. Yeah, we're

20
00:00:53.600 --> 00:00:55.780 A:middle L:90%
basically rebuilding the character control and unity, but this

21
00:00:55.780 --> 00:00:57.740 A:middle L:90%
just tends to work a lot better. So for

22
00:00:57.740 --> 00:00:59.780 A:middle L:90%
the beta character who wanted to drag in his physic

23
00:00:59.780 --> 00:01:02.929 A:middle L:90%
material that's already pre made and we want to just

24
00:01:02.929 --> 00:01:07.159 A:middle L:90%
resize this capsule glider so it fits him better or

25
00:01:07.159 --> 00:01:08.819 A:middle L:90%
her. It's really hard to tell. Um so

26
00:01:08.819 --> 00:01:11.760 A:middle L:90%
.5 is a little big, we'll make it .4

27
00:01:11.140 --> 00:01:17.549 A:middle L:90%
and we're going to move this Y value. So

28
00:01:17.549 --> 00:01:22.159 A:middle L:90%
we're gonna go with a Y value of 0.97 It's

29
00:01:22.159 --> 00:01:26.010 A:middle L:90%
about as tall as it is. Yeah. And

30
00:01:26.010 --> 00:01:30.359 A:middle L:90%
we want to move the height so that it is

31
00:01:30.739 --> 00:01:33.359 A:middle L:90%
Uh two meters tall so that that it's a lot

32
00:01:33.359 --> 00:01:36.760 A:middle L:90%
better. Okay, cool. So the rigid body,

33
00:01:37.140 --> 00:01:38.680 A:middle L:90%
you can just estimate the mass. I feel

34
00:01:38.680 --> 00:01:41.709 A:middle L:90%
like, I don't know about 100 is probably good

35
00:01:41.709 --> 00:01:44.170 A:middle L:90%
enough and you want to make sure that it is

36
00:01:44.170 --> 00:01:47.700 A:middle L:90%
using gravity and that should do us all right.

37
00:01:47.700 --> 00:01:51.099 A:middle L:90%
So now we're ready to um to save this.

38
00:01:52.040 --> 00:01:53.659 A:middle L:90%
Let's do the same thing in our other scene.

39
00:01:53.140 --> 00:01:55.950 A:middle L:90%
So we've got our debug scene over here that we're

40
00:01:55.950 --> 00:01:59.060 A:middle L:90%
just testing locomotion in and you notice that this hasn't

41
00:01:59.060 --> 00:02:00.859 A:middle L:90%
been set here and the way that you want to

42
00:02:00.859 --> 00:02:02.170 A:middle L:90%
transfer the values over since we have a prefab for

43
00:02:02.170 --> 00:02:07.219 A:middle L:90%
our character set apply and then go back and you'll

44
00:02:07.219 --> 00:02:08.819 A:middle L:90%
see that the beta character now has all of those

45
00:02:08.819 --> 00:02:14.370 A:middle L:90%
things attached to him. So that's really handy. Okay,

46
00:02:14.370 --> 00:02:15.500 A:middle L:90%
so the next thing I want to do is you

47
00:02:15.500 --> 00:02:16.979 A:middle L:90%
want to set up the characters Mecanim, animation trees.

48
00:02:16.979 --> 00:02:19.860 A:middle L:90%
So we'll go into his character controller here.

49
00:02:20.240 --> 00:02:22.539 A:middle L:90%
We want to start dragging in some animations. So

50
00:02:22.539 --> 00:02:23.430 A:middle L:90%
you want an idle animation first. And for that

51
00:02:23.430 --> 00:02:27.219 A:middle L:90%
we're gonna use this player idle animation. So let's

52
00:02:27.219 --> 00:02:30.900 A:middle L:90%
preview that really first and let's make sure that it

53
00:02:30.900 --> 00:02:38.569 A:middle L:90%
worked cool. It's subtle but he's idling. So

54
00:02:38.569 --> 00:02:39.240 A:middle L:90%
what you do to get that in the Mecanim trees,

55
00:02:39.240 --> 00:02:43.129 A:middle L:90%
you just find the animation, drag the clip

56
00:02:43.139 --> 00:02:46.740 A:middle L:90%
into the tree and hopefully character of side animating.

57
00:02:46.900 --> 00:02:49.719 A:middle L:90%
He fell through the fell to the floor, see

58
00:02:49.719 --> 00:02:52.740 A:middle L:90%
what happens. And it's probably because we did not

59
00:02:52.740 --> 00:02:53.710 A:middle L:90%
add mesh colliders to our world. So we should

60
00:02:53.710 --> 00:02:57.120 A:middle L:90%
probably do that. So add mesh colliders to both of

61
00:02:57.120 --> 00:02:59.270 A:middle L:90%
these for the roof. We probably actually don't need

62
00:02:59.270 --> 00:03:00.919 A:middle L:90%
one. So you can you can remove that.

63
00:03:00.919 --> 00:03:01.759 A:middle L:90%
We'll just add it to the to the main floor

64
00:03:02.439 --> 00:03:05.090 A:middle L:90%
. And we need to also have a rigid body

65
00:03:05.090 --> 00:03:07.849 A:middle L:90%
component. So the rigid body same thing. Get

66
00:03:07.849 --> 00:03:10.789 A:middle L:90%
a big mass. Turn off gravity. Turn on

67
00:03:10.800 --> 00:03:15.849 A:middle L:90%
kinematic. Yeah, not falling through the floor now.

68
00:03:15.340 --> 00:03:17.020 A:middle L:90%
So if you'll notice I got a bit of

69
00:03:17.020 --> 00:03:20.430 A:middle L:90%
a problem here. He's not moving So to do

70
00:03:20.430 --> 00:03:22.919 A:middle L:90%
that, we want to extend this animation tree and

71
00:03:22.919 --> 00:03:24.789 A:middle L:90%
create a new node in our state machine here for

72
00:03:24.789 --> 00:03:28.159 A:middle L:90%
running. So to do that, let's have a

73
00:03:28.159 --> 00:03:30.759 A:middle L:90%
look at the other animations we have available to us

74
00:03:30.439 --> 00:03:31.719 A:middle L:90%
. And what we want to do is create a

75
00:03:31.719 --> 00:03:35.469 A:middle L:90%
blend tree and what a blend tree is is a

76
00:03:35.469 --> 00:03:38.379 A:middle L:90%
node that can take an input and then blend between

77
00:03:38.389 --> 00:03:40.599 A:middle L:90%
various various nodes based on that input. So it's

78
00:03:40.599 --> 00:03:43.669 A:middle L:90%
really great if you want to have a speed of

79
00:03:43.669 --> 00:03:45.330 A:middle L:90%
one, be a walk, a speed of two

80
00:03:45.330 --> 00:03:47.159 A:middle L:90%
be a run and a speed of five be like

81
00:03:47.159 --> 00:03:49.900 A:middle L:90%
a sprint or something like that. So in our

82
00:03:49.900 --> 00:03:52.060 A:middle L:90%
new blend tree, we'll just call this thing locomotion.

83
00:03:53.069 --> 00:03:55.460 A:middle L:90%
And we're gonna want to drag in our run

84
00:03:55.460 --> 00:03:59.509 A:middle L:90%
animations. It sounds like in our animation folder.

85
00:03:59.699 --> 00:04:02.650 A:middle L:90%
We got running animations for run. We've got this

86
00:04:02.650 --> 00:04:06.060 A:middle L:90%
animation here. It's just our character running in a

87
00:04:06.060 --> 00:04:11.159 A:middle L:90%
straight line. So go ahead and use this one

88
00:04:12.039 --> 00:04:15.220 A:middle L:90%
drag that into our country just by going add motion

89
00:04:15.220 --> 00:04:19.209 A:middle L:90%
field searching here and we can just type run and

90
00:04:19.209 --> 00:04:23.029 A:middle L:90%
then selecting that animation. Okay, cool. So

91
00:04:23.029 --> 00:04:24.889 A:middle L:90%
now we've got this blen tree right now. It's

92
00:04:24.889 --> 00:04:27.620 A:middle L:90%
not really blending. It's basically just the same thing

93
00:04:27.620 --> 00:04:29.310 A:middle L:90%
as if we just drop the animation in on this

94
00:04:29.310 --> 00:04:30.639 A:middle L:90%
layer and we want to be able to blend between

95
00:04:30.639 --> 00:04:32.819 A:middle L:90%
different values based on like a direction that the characters

96
00:04:32.819 --> 00:04:34.540 A:middle L:90%
running. So to do that we're going to go

97
00:04:34.540 --> 00:04:38.399 A:middle L:90%
to our animations again. We're gonna have a look

98
00:04:38.399 --> 00:04:41.560 A:middle L:90%
at what runs we have, we've got a run

99
00:04:42.240 --> 00:04:46.759 A:middle L:90%
left and never run white right, and we have

100
00:04:46.759 --> 00:04:48.160 A:middle L:90%
them for medium wide and short. So we can

101
00:04:48.160 --> 00:04:51.009 A:middle L:90%
blend between those runs. So let's go ahead and

102
00:04:51.009 --> 00:04:55.660 A:middle L:90%
do that. Mhm add new fields to this.

103
00:04:56.339 --> 00:04:59.360 A:middle L:90%
So at a motion field I had one more motion

104
00:04:59.360 --> 00:05:01.129 A:middle L:90%
fields. And what we want to do is want

105
00:05:01.129 --> 00:05:03.870 A:middle L:90%
to drag in our run animations. So let's make

106
00:05:03.870 --> 00:05:05.449 A:middle L:90%
sure that these work first. Just test them.

107
00:05:06.240 --> 00:05:09.389 A:middle L:90%
Okay cool. We've got our character running in a

108
00:05:09.389 --> 00:05:13.860 A:middle L:90%
circle so what so click on the country and Dragon

109
00:05:14.540 --> 00:05:18.370 A:middle L:90%
run right and Dragon run left. So we want

110
00:05:18.370 --> 00:05:20.089 A:middle L:90%
to do is want to we want to on click

111
00:05:20.089 --> 00:05:23.720 A:middle L:90%
automate thresholds and these are the thresholds for the input

112
00:05:23.720 --> 00:05:25.730 A:middle L:90%
value that we're going to be feeding in and what

113
00:05:25.730 --> 00:05:28.149 A:middle L:90%
their what they correspond to. So for running left

114
00:05:28.149 --> 00:05:30.399 A:middle L:90%
we're gonna call that negative one. I'm gonna call

115
00:05:30.399 --> 00:05:31.730 A:middle L:90%
running forward zero. I'm going to call running right

116
00:05:31.740 --> 00:05:34.600 A:middle L:90%
one. And you want to adjust the time scales,

117
00:05:34.600 --> 00:05:36.040 A:middle L:90%
you want to homogenize them. And basically this

118
00:05:36.040 --> 00:05:40.209 A:middle L:90%
means that one loop of the animation is now the

119
00:05:40.209 --> 00:05:42.949 A:middle L:90%
same length, three twenties animations. So they'll be

120
00:05:42.949 --> 00:05:44.550 A:middle L:90%
sped up or slowed down to make them all the

121
00:05:44.550 --> 00:05:46.730 A:middle L:90%
same length already. So let's choose our parameter.

122
00:05:46.829 --> 00:05:48.660 A:middle L:90%
Right now, we have no parameters in our animation

123
00:05:48.660 --> 00:05:50.660 A:middle L:90%
controller. So let's add a new one, give

124
00:05:50.660 --> 00:05:56.259 A:middle L:90%
me a float, we'll call this direction. Cool.

125
00:05:56.740 --> 00:05:59.410 A:middle L:90%
So now we can preview this blend tree and

126
00:05:59.410 --> 00:06:00.750 A:middle L:90%
if we just slide this slider we can see our

127
00:06:00.750 --> 00:06:04.879 A:middle L:90%
guy run right, or left. So cool.

128
00:06:04.889 --> 00:06:08.610 A:middle L:90%
We now know that our animations are working pretty well.

129
00:06:08.620 --> 00:06:11.149 A:middle L:90%
This preview is super handy. So now let's

130
00:06:11.149 --> 00:06:13.600 A:middle L:90%
set up a transition between these two things. It's

131
00:06:13.600 --> 00:06:15.399 A:middle L:90%
called a blend, three Locomotion. Even though it's

132
00:06:15.399 --> 00:06:17.730 A:middle L:90%
really just running right now, do you want to

133
00:06:17.730 --> 00:06:20.120 A:middle L:90%
right click this, make a transition and make a

134
00:06:20.120 --> 00:06:21.970 A:middle L:90%
transition. So you want to know what you're basically

135
00:06:21.970 --> 00:06:25.839 A:middle L:90%
saying. The character should be able to run from

136
00:06:25.839 --> 00:06:27.540 A:middle L:90%
idle and should be able to go to idle from

137
00:06:27.540 --> 00:06:30.180 A:middle L:90%
run. So we want to here you just want

138
00:06:30.180 --> 00:06:31.670 A:middle L:90%
to make this uh we want to make some condition

139
00:06:31.670 --> 00:06:33.230 A:middle L:90%
for him running. And to do that. We're

140
00:06:33.230 --> 00:06:35.350 A:middle L:90%
going to make a new thing called speed. So

141
00:06:35.350 --> 00:06:40.149 A:middle L:90%
make a new float. So when he runs faster

142
00:06:40.149 --> 00:06:43.500 A:middle L:90%
than some Value, that means we should enter into

143
00:06:43.500 --> 00:06:46.120 A:middle L:90%
the locomotion state. So we're gonna set that value

144
00:06:46.129 --> 00:06:49.060 A:middle L:90%
speed to greater than .5. So now our state

145
00:06:49.060 --> 00:06:51.600 A:middle L:90%
machine will enter into the locomotion state if this parameter

146
00:06:51.600 --> 00:06:56.769 A:middle L:90%
called speed is greater than five and that's it for

147
00:06:56.769 --> 00:06:58.949 A:middle L:90%
that. And now let's make our transition out.

148
00:06:59.839 --> 00:07:01.060 A:middle L:90%
We want to do here is say if the speed

149
00:07:01.839 --> 00:07:09.259 A:middle L:90%
is less than 0.5 takes it Actually at some .05,

150
00:07:09.269 --> 00:07:11.889 A:middle L:90%
that will make him slow down. So this

151
00:07:11.889 --> 00:07:14.250 A:middle L:90%
would basically be if you let off the stick it

152
00:07:14.250 --> 00:07:15.149 A:middle L:90%
will transition back to idle, which is what we

153
00:07:15.149 --> 00:07:18.250 A:middle L:90%
want. Okay so here we want to make sure

154
00:07:18.250 --> 00:07:21.339 A:middle L:90%
that atomic is unchecked. Basically. What this means

155
00:07:21.350 --> 00:07:25.579 A:middle L:90%
is if atomic has checked this locomotion note has to

156
00:07:25.579 --> 00:07:28.329 A:middle L:90%
go all the way to completion before it'll time out

157
00:07:28.339 --> 00:07:29.910 A:middle L:90%
And we want to be able to stop whenever

158
00:07:29.920 --> 00:07:30.910 A:middle L:90%
because you don't want to have the user press forward

159
00:07:30.910 --> 00:07:32.620 A:middle L:90%
on the control stick, expect to stop and they

160
00:07:32.620 --> 00:07:34.839 A:middle L:90%
let go and then stop three seconds later when the

161
00:07:34.839 --> 00:07:36.350 A:middle L:90%
run cycles finished. So I want to make sure

162
00:07:36.350 --> 00:07:40.009 A:middle L:90%
that atomic is unchecked. Mhm. Alright great.

163
00:07:40.009 --> 00:07:41.490 A:middle L:90%
So let's check this out real fast. Let's see

164
00:07:41.490 --> 00:07:44.569 A:middle L:90%
if we've got what it looks like when the character

165
00:07:44.569 --> 00:07:46.339 A:middle L:90%
starts running right? The blend looks pretty good there

166
00:07:46.350 --> 00:07:47.750 A:middle L:90%
and let's see what it looks like when he stops.

167
00:07:49.040 --> 00:07:51.620 A:middle L:90%
Perfect. Alright cool. Now let's make sure

168
00:07:51.629 --> 00:07:55.259 A:middle L:90%
that we're actually supplying these parameters to the animation controller

169
00:07:55.259 --> 00:07:56.949 A:middle L:90%
now and the way they were gonna do that is

170
00:07:56.949 --> 00:07:59.620 A:middle L:90%
through a script on our character. So let's save

171
00:07:59.620 --> 00:08:01.959 A:middle L:90%
our senior fast and on beta. Just implicated him

172
00:08:03.339 --> 00:08:05.379 A:middle L:90%
on beta. We want to create a new script.

173
00:08:05.389 --> 00:08:07.139 A:middle L:90%
So we're gonna add component. We're gonna call

174
00:08:07.139 --> 00:08:13.949 A:middle L:90%
this script character logic. So actually probably character controller

175
00:08:13.949 --> 00:08:18.180 A:middle L:90%
logic is the logic behind our character controller. We're

176
00:08:18.180 --> 00:08:20.949 A:middle L:90%
gonna choose C Sharp as our language created and added.

177
00:08:22.939 --> 00:08:24.029 A:middle L:90%
So we're going to open this guy up and

178
00:08:24.029 --> 00:08:39.059 A:middle L:90%
want to develop. Now once the script loaded,

179
00:08:39.059 --> 00:08:41.629 A:middle L:90%
you'll see that there's actually a bunch of code that's

180
00:08:41.629 --> 00:08:43.240 A:middle L:90%
already in there. And what that comes from is

181
00:08:43.240 --> 00:08:48.259 A:middle L:90%
basically there is a file in this data folder called

182
00:08:48.840 --> 00:08:54.070 A:middle L:90%
the script template. That's right here. And what

183
00:08:54.070 --> 00:08:58.899 A:middle L:90%
this text file is is basically just whenever a new

184
00:08:58.899 --> 00:09:01.029 A:middle L:90%
script gets made, all of this stuff is automatically

185
00:09:01.029 --> 00:09:03.889 A:middle L:90%
supplied. What I've done here is I've made region

186
00:09:03.889 --> 00:09:05.889 A:middle L:90%
tags for each one of the parts of the file.

187
00:09:05.889 --> 00:09:07.139 A:middle L:90%
So we've got our unity event functions like uh,

188
00:09:07.149 --> 00:09:09.470 A:middle L:90%
start update, draw, gizmos, things like

189
00:09:09.470 --> 00:09:11.659 A:middle L:90%
that. We've got a section for methods, section

190
00:09:11.659 --> 00:09:13.840 A:middle L:90%
for properties in a section for variables. So this

191
00:09:13.840 --> 00:09:16.759 A:middle L:90%
is pretty useful and it's just really handy when you're

192
00:09:16.759 --> 00:09:20.090 A:middle L:90%
creating new classes a bunch. All right, let's

193
00:09:20.090 --> 00:09:20.259 A:middle L:90%
go ahead. And our logic in here.

