1
00:00:00,000 --> 00:00:03,930
Welcome back my fellow game developers to one of the

2
00:00:03,930 --> 00:00:08,010
more exciting and long, very long videos.

3
00:00:08,010 --> 00:00:10,850
But trust me, it's very worth it.

4
00:00:10,845 --> 00:00:17,435
In this video, we are going to inject more life and to our game by creating animations.

5
00:00:17,430 --> 00:00:19,650
So now when we start our game,

6
00:00:19,650 --> 00:00:22,200
we don't just stand there like a statue.

7
00:00:22,200 --> 00:00:24,830
You can see that we are moving.

8
00:00:24,825 --> 00:00:26,885
So our player is going up and down,

9
00:00:26,880 --> 00:00:28,400
up and down, up and down.

10
00:00:28,395 --> 00:00:29,765
And not only that,

11
00:00:29,760 --> 00:00:32,900
whenever we start walking, look at that.

12
00:00:32,900 --> 00:00:35,170
He starts moving his feet around.

13
00:00:35,165 --> 00:00:36,695
How cool is that?

14
00:00:36,695 --> 00:00:41,255
Seriously, now we don't have just the player standing fair lucky statue.

15
00:00:41,255 --> 00:00:44,325
He actually has life, his breathing.

16
00:00:44,329 --> 00:00:46,539
He's walking, he's looking around,

17
00:00:46,535 --> 00:00:47,855
he's pointing his gun,

18
00:00:47,855 --> 00:00:49,585
he's ready to start shooting.

19
00:00:49,580 --> 00:00:51,520
He still needs a bit of tweaking,

20
00:00:51,515 --> 00:00:54,065
but we'll handle that in the next video.

21
00:00:54,065 --> 00:00:57,415
So what actually, on the end, which video?

22
00:00:57,410 --> 00:01:02,030
Let's not waste any more time thinking and let's get to animating.

23
00:01:02,030 --> 00:01:03,650
Oh, okay.

24
00:01:03,650 --> 00:01:07,510
So currently when we start our game,

25
00:01:07,505 --> 00:01:09,475
if we move around,

26
00:01:09,470 --> 00:01:11,900
as you can see, we are very stale.

27
00:01:11,900 --> 00:01:14,770
We don't have any animations in particular,

28
00:01:14,765 --> 00:01:17,545
we don't see the player changing states

29
00:01:17,540 --> 00:01:20,560
when he starts walking or when he's standing either.

30
00:01:20,555 --> 00:01:22,625
So we're going to change that.

31
00:01:22,625 --> 00:01:25,895
We are going to add animations to our player.

32
00:01:25,895 --> 00:01:29,915
And we already have a couple of spreadsheets and here,

33
00:01:29,915 --> 00:01:32,695
those that will determine our animation.

34
00:01:32,690 --> 00:01:35,900
So you can see the idling, the walking.

35
00:01:35,900 --> 00:01:40,390
We're going to put them side-by-side and play these sprites as we walk,

36
00:01:40,385 --> 00:01:41,695
as we stand still,

37
00:01:41,690 --> 00:01:44,340
as we do the torpedo movement.

38
00:01:44,344 --> 00:01:47,304
So let's get started with animations.

39
00:01:47,300 --> 00:01:51,190
First thing first, let's understand what animations are.

40
00:01:51,185 --> 00:01:54,115
A couple of key components that we need.

41
00:01:54,110 --> 00:01:57,020
First of all, we have the animator controller,

42
00:01:57,020 --> 00:02:01,850
which allows you to arrange and maintain a set of animations clip.

43
00:02:01,850 --> 00:02:08,810
We have the animator component which we add to any game object that we want to animate.

44
00:02:08,810 --> 00:02:11,210
We have the actual animations,

45
00:02:11,210 --> 00:02:14,870
which are several sprites are rendered one after the other.

46
00:02:14,870 --> 00:02:19,040
We'll also see that we have a another type of animations that allow us to

47
00:02:19,040 --> 00:02:23,560
move objects and then remember it and play it at certain times.

48
00:02:23,555 --> 00:02:25,985
And finally we have the sprite renderer.

49
00:02:25,985 --> 00:02:29,525
Now, why am I reminding you of the sprite renderer?

50
00:02:29,525 --> 00:02:31,315
Because in just a bit,

51
00:02:31,310 --> 00:02:36,500
you'll need to understand which sprite renderer would actually trying to

52
00:02:36,500 --> 00:02:41,680
change in order to create the animations that we have for our DOM player.

53
00:02:41,675 --> 00:02:43,285
Okay, enough talking.

54
00:02:43,280 --> 00:02:45,250
Let's get started with animations.

55
00:02:45,245 --> 00:02:48,115
So let's go into Unity.

56
00:02:48,110 --> 00:02:52,870
And the first thing that we need to do is we need to get the windows for the animation.

57
00:02:52,865 --> 00:02:55,645
So we're going to create the animations window.

58
00:02:55,640 --> 00:02:58,120
Let's dock it around here.

59
00:02:58,115 --> 00:02:59,335
And let's create a,

60
00:02:59,330 --> 00:03:02,090
another window for the animator.

61
00:03:02,090 --> 00:03:03,140
There you go.

62
00:03:03,140 --> 00:03:07,910
So the animator as where we are going to set all of the animations.

63
00:03:07,910 --> 00:03:12,130
And the animations as where we will actually create the animations.

64
00:03:12,125 --> 00:03:14,635
Let's get started. First thing first,

65
00:03:14,630 --> 00:03:17,480
we're going to choose our doom player.

66
00:03:17,480 --> 00:03:20,230
And as you can see immediately in the animation window,

67
00:03:20,225 --> 00:03:22,525
we have to begin animating, do player,

68
00:03:22,520 --> 00:03:25,160
create an animator and animation clip.

69
00:03:25,160 --> 00:03:26,750
Great, Let's do that.

70
00:03:26,750 --> 00:03:28,670
We're going to hit Create.

71
00:03:28,670 --> 00:03:34,540
And as you can see, we are currently in the time both invader file and the assets.

72
00:03:34,535 --> 00:03:37,205
I'm going to create a new folder in here,

73
00:03:37,205 --> 00:03:40,735
which is going to be the animations.

74
00:03:40,730 --> 00:03:43,250
Or animation's.

75
00:03:43,250 --> 00:03:44,230
There you go.

76
00:03:44,225 --> 00:03:49,115
And in here create a folder called the player.

77
00:03:49,115 --> 00:03:52,015
And we are going to name our clip.

78
00:03:52,010 --> 00:03:54,800
Let's start by creating a player,

79
00:03:54,800 --> 00:03:57,800
I think. Okay, great.

80
00:03:57,800 --> 00:04:00,590
So now we have our new animation.

81
00:04:00,590 --> 00:04:02,510
And if we look on the dome player,

82
00:04:02,510 --> 00:04:07,340
you can see that we have a new component next to the rigid body and the capsule,

83
00:04:07,340 --> 00:04:09,320
which is the animator.

84
00:04:09,320 --> 00:04:10,990
So if we go into the scene,

85
00:04:10,985 --> 00:04:13,475
nothing changes but inside of the animator,

86
00:04:13,475 --> 00:04:14,935
just to refresh everything,

87
00:04:14,930 --> 00:04:19,660
you can see that we now have these little rectangles in here.

88
00:04:19,655 --> 00:04:21,115
And what are these?

89
00:04:21,110 --> 00:04:23,270
Well, we have the any state,

90
00:04:23,270 --> 00:04:24,740
the entry and exit.

91
00:04:24,740 --> 00:04:27,820
Let's not worry about the any state and the exit.

92
00:04:27,815 --> 00:04:31,495
Let's focus on the entry and the actual player idling.

93
00:04:31,490 --> 00:04:35,110
What this means is as soon as we start our game,

94
00:04:35,105 --> 00:04:38,585
we immediately transition into the player idling.

95
00:04:38,585 --> 00:04:42,335
And you will see that every single time we have an animator,

96
00:04:42,335 --> 00:04:46,435
we always have a default animation that we start off with.

97
00:04:46,430 --> 00:04:51,920
And in this case, we have the player idling starting immediately from the entry.

98
00:04:51,920 --> 00:04:56,480
And as you can see, it's connected by this line with an arrow.

99
00:04:56,480 --> 00:04:58,370
This is called a transition.

100
00:04:58,370 --> 00:05:04,070
And later on we will be making our own transition to go from one animation to the other.

101
00:05:04,070 --> 00:05:06,050
Okay, let's continue on.

102
00:05:06,050 --> 00:05:11,060
The next thing we want to do is we actually want to create the animation.

103
00:05:11,060 --> 00:05:12,970
So in order to do that,

104
00:05:12,965 --> 00:05:16,465
we need to get our idling sprites right here.

105
00:05:16,460 --> 00:05:21,040
Those three, we want to add them to the player and start playing with them.

106
00:05:21,035 --> 00:05:26,005
But there is a small detail in here that we need to take into consideration.

107
00:05:26,000 --> 00:05:30,650
We are going to be changing the sprites of the player.

108
00:05:30,650 --> 00:05:35,050
And the sprites that we are changing are actually on the body,

109
00:05:35,045 --> 00:05:37,025
not on the immediate.

110
00:05:37,025 --> 00:05:39,055
Doing player game object.

111
00:05:39,050 --> 00:05:41,740
So through this animation,

112
00:05:41,735 --> 00:05:44,605
will need to add a property in here.

113
00:05:44,600 --> 00:05:47,620
And let me just explain this window right here.

114
00:05:47,615 --> 00:05:49,705
This is the timeline for the animation.

115
00:05:49,700 --> 00:05:51,980
So you can see from 030,

116
00:05:51,980 --> 00:05:54,980
this is 2.5th and 2 one right here.

117
00:05:54,980 --> 00:05:56,950
This is a whole second.

118
00:05:56,945 --> 00:05:58,385
You have the play,

119
00:05:58,385 --> 00:06:01,355
the go-to next keyframe, et cetera.

120
00:06:01,355 --> 00:06:04,235
You have the Record button here and you can create

121
00:06:04,235 --> 00:06:07,825
a new clip by clicking on this drop-down right here.

122
00:06:07,820 --> 00:06:10,490
So let's add a property.

123
00:06:10,490 --> 00:06:13,550
When we click it, you can see that we have access to

124
00:06:13,550 --> 00:06:19,610
all the components that are present on the player or the doom player game object,

125
00:06:19,610 --> 00:06:22,210
we can change the weapons are the Chicago,

126
00:06:22,205 --> 00:06:24,355
the arm, the body, everything.

127
00:06:24,350 --> 00:06:27,410
So I'm going to access the body.

128
00:06:27,410 --> 00:06:31,160
And you can see that I can access the sprite render on it.

129
00:06:31,160 --> 00:06:32,890
And if I scroll down,

130
00:06:32,885 --> 00:06:38,845
I can actually access the sprite which is on the body right here.

131
00:06:38,840 --> 00:06:42,320
So I'm going to click on the little plus sign here.

132
00:06:42,320 --> 00:06:45,500
If I make this a bit bigger,

133
00:06:45,500 --> 00:06:47,810
you can see that I can actually see

134
00:06:47,810 --> 00:06:50,900
this little sprite and this is what we're going to change.

135
00:06:50,900 --> 00:06:52,670
So if I hit Play,

136
00:06:52,670 --> 00:06:58,250
you'll notice that nothing changes because this sprite is exactly the same as this one.

137
00:06:58,250 --> 00:07:00,250
So let's change that.

138
00:07:00,245 --> 00:07:04,625
I'm going to dock the animations and here just to have a little bit of space,

139
00:07:04,625 --> 00:07:07,025
I'm going to delete the last one,

140
00:07:07,025 --> 00:07:08,695
Keep this right here.

141
00:07:08,690 --> 00:07:14,090
I'm going to select these three and add them to the timeline right here,

142
00:07:14,090 --> 00:07:16,450
and I can get rid of the first one.

143
00:07:16,445 --> 00:07:21,255
So now let me just make these, okay, But apart.

144
00:07:21,259 --> 00:07:24,159
I'll dock the animation back here.

145
00:07:24,155 --> 00:07:28,715
And now if I tried to play the animation, there you go.

146
00:07:28,715 --> 00:07:31,705
You can see that our player starts to move.

147
00:07:31,700 --> 00:07:33,310
How cool is that?

148
00:07:33,305 --> 00:07:34,825
What is happening in here?

149
00:07:34,820 --> 00:07:36,170
If you look closely,

150
00:07:36,170 --> 00:07:38,290
let me just pause this for a second.

151
00:07:38,285 --> 00:07:44,065
I'll just make the time between each a bit far away.

152
00:07:44,060 --> 00:07:45,310
So now when we play,

153
00:07:45,305 --> 00:07:48,815
you'll notice that we are going from one sprite to the other.

154
00:07:48,815 --> 00:07:52,195
And you can make sure of that by looking right here on

155
00:07:52,190 --> 00:07:55,630
the inspector of the body and see that we are going from either one,

156
00:07:55,625 --> 00:07:57,955
either to idle, want idle two.

157
00:07:57,950 --> 00:07:59,870
And this one right here,

158
00:07:59,870 --> 00:08:01,160
which is the three,

159
00:08:01,160 --> 00:08:04,930
is barely being played because as soon as we get to the end,

160
00:08:04,925 --> 00:08:07,565
we then immediately start from the beginning.

161
00:08:07,565 --> 00:08:14,755
So a good, let's say principal to have on creating animations is that all the time,

162
00:08:14,750 --> 00:08:21,970
the first frame should be copied by pressing Control C and B,

163
00:08:21,965 --> 00:08:23,455
the last frame also.

164
00:08:23,450 --> 00:08:26,440
So now you'll notice how the animation looks much better.

165
00:08:26,435 --> 00:08:29,075
So I'm going to play the animation again.

166
00:08:29,075 --> 00:08:30,385
There you go.

167
00:08:30,380 --> 00:08:32,510
You can see that now we are idling.

168
00:08:32,510 --> 00:08:34,700
We can see 1, 2, 3,

169
00:08:34,700 --> 00:08:37,820
1, 2, 3 playing one after the other.

170
00:08:37,820 --> 00:08:41,540
So now we have the animation of the player idling.

171
00:08:41,540 --> 00:08:43,550
And if we run our gain,

172
00:08:43,550 --> 00:08:45,710
you can see that as soon as we start,

173
00:08:45,710 --> 00:08:47,840
the player starts either link.

174
00:08:47,840 --> 00:08:49,660
And even while we are moving,

175
00:08:49,655 --> 00:08:50,975
we are still idling.

176
00:08:50,975 --> 00:08:52,535
Even if we look the other way,

177
00:08:52,535 --> 00:08:54,415
we are still idling.

178
00:08:54,410 --> 00:08:56,480
And if we check the animator,

179
00:08:56,480 --> 00:09:00,250
you can see that all the time we are idling.

180
00:09:00,245 --> 00:09:04,255
I'll lock it right here so we can see it clearly and zoom out a bit.

181
00:09:04,250 --> 00:09:09,770
So this is the player idling all the time while we are standing, still.

182
00:09:09,770 --> 00:09:10,610
Great.

183
00:09:10,610 --> 00:09:17,060
Now, the next step is to go ahead and create the walking animation.

184
00:09:17,059 --> 00:09:21,879
And it's going to be your challenge.

185
00:09:21,875 --> 00:09:25,055
Your challenge is to create another animation.

186
00:09:25,055 --> 00:09:28,415
So get the walking sprites from the main sprite.

187
00:09:28,415 --> 00:09:30,775
If you haven't already slice that up,

188
00:09:30,770 --> 00:09:36,630
choose the doom player in the hierarchy and create a new clip like I showed you.

189
00:09:36,630 --> 00:09:40,360
Add all the walking sprites and separate them.

190
00:09:40,360 --> 00:09:43,950
Play around and make the walking look good.

191
00:09:43,945 --> 00:09:47,185
And if you are interested in an extra challenge,

192
00:09:47,185 --> 00:09:50,365
you can go ahead and create the torpedo animation.

193
00:09:50,365 --> 00:09:53,535
I'm not sure if I'm going to keep using the torpedo animation.

194
00:09:53,530 --> 00:09:55,120
Maybe it should be something different,

195
00:09:55,120 --> 00:09:57,910
maybe v, rolling around animation.

196
00:09:57,910 --> 00:09:59,770
I don't know with that non,

197
00:09:59,770 --> 00:10:01,450
pause the video right now,

198
00:10:01,450 --> 00:10:03,160
go try out the animation.

199
00:10:03,160 --> 00:10:05,320
Don't worry, even if you're a beginner,

200
00:10:05,320 --> 00:10:06,720
just try it out.

201
00:10:06,715 --> 00:10:07,965
See a couple of steps.

202
00:10:07,960 --> 00:10:10,110
How I created the idling.

203
00:10:10,105 --> 00:10:12,925
Try it yourself, have fun, enjoy.

204
00:10:12,925 --> 00:10:15,085
And that's it.

205
00:10:15,085 --> 00:10:20,005
Pause the video right now and go do it each challenge.

206
00:10:20,130 --> 00:10:25,390
Okay, so now we are going to create the second animation,

207
00:10:25,390 --> 00:10:26,670
which is the walking.

208
00:10:26,665 --> 00:10:29,275
So I'm going to click in here.

209
00:10:29,275 --> 00:10:31,665
I'm going to create a new clip.

210
00:10:31,660 --> 00:10:35,900
Go to the animations player, choose idling,

211
00:10:35,904 --> 00:10:37,554
and instead of idling,

212
00:10:37,555 --> 00:10:41,595
I'm going to set it as the walking.

213
00:10:41,590 --> 00:10:43,890
So now player is walking.

214
00:10:43,885 --> 00:10:44,895
Very good.

215
00:10:44,890 --> 00:10:49,270
Okay, so now we are going to add a property in here.

216
00:10:49,270 --> 00:10:52,000
We are going to access the body because remember

217
00:10:51,999 --> 00:10:55,619
the sprites that we are changing are on the body.

218
00:10:55,615 --> 00:11:01,815
Sprite renderer, the sprite because we are actually changing each single sprite.

219
00:11:01,815 --> 00:11:03,655
And we are going to add,

220
00:11:03,650 --> 00:11:06,340
let's move the animation in here.

221
00:11:06,335 --> 00:11:08,785
Maybe this is not the best place to add an animation,

222
00:11:08,780 --> 00:11:11,660
but we'll just have to do with what we have for now.

223
00:11:11,660 --> 00:11:13,160
Go to the project,

224
00:11:13,160 --> 00:11:15,140
which are our walking.

225
00:11:15,140 --> 00:11:18,800
So I think these last four are the walking out.

226
00:11:18,800 --> 00:11:20,620
Just add them in here.

227
00:11:20,615 --> 00:11:23,885
I'll remove the last one and the first one.

228
00:11:23,885 --> 00:11:26,365
That started the animation back down.

229
00:11:26,360 --> 00:11:31,360
Let's choose all of these and I'm going to spread them out

230
00:11:31,355 --> 00:11:37,495
with an interval of 10. Let's make it 10.

231
00:11:37,490 --> 00:11:41,230
So 10, 10, 10.

232
00:11:41,225 --> 00:11:45,335
And I'm going to copy the first one and set it as the last one.

233
00:11:45,335 --> 00:11:48,275
And now when we tried to play the animation,

234
00:11:48,275 --> 00:11:51,695
there we go, you can see the walking of the player.

235
00:11:51,695 --> 00:11:52,945
And correct.

236
00:11:52,940 --> 00:11:56,600
Now, how are we going to transition?

237
00:11:56,600 --> 00:11:58,550
And if you actually click on the animator,

238
00:11:58,550 --> 00:12:03,790
you'll see that we now have a new clip in here which is the player walking.

239
00:12:03,785 --> 00:12:08,225
But how are we going to transition from widening talking?

240
00:12:08,224 --> 00:12:10,444
This is the $1 million question.

241
00:12:10,445 --> 00:12:12,745
Before I tell you how we do that,

242
00:12:12,740 --> 00:12:17,800
let me just show you what we've created in this Animations folder inside of the player.

243
00:12:17,795 --> 00:12:20,485
So we have the doom player,

244
00:12:20,480 --> 00:12:22,250
he has an animator,

245
00:12:22,250 --> 00:12:24,080
he has a controller.

246
00:12:24,080 --> 00:12:26,450
And if I click on the controller, by the way,

247
00:12:26,450 --> 00:12:28,940
whenever you click, for example, on the don't player,

248
00:12:28,940 --> 00:12:32,600
you can see the rigid body where it is or the weapons on,

249
00:12:32,600 --> 00:12:34,340
can get a reference.

250
00:12:34,340 --> 00:12:36,130
We click on the controller.

251
00:12:36,125 --> 00:12:38,515
This is the controller and these are

252
00:12:38,510 --> 00:12:42,530
the animations of the player and the walking, the idling.

253
00:12:42,530 --> 00:12:47,140
And you can see right here, we can do a bit of a modification for the cycle offset,

254
00:12:47,135 --> 00:12:50,005
the loop time, the loop poles.

255
00:12:50,000 --> 00:12:53,920
But for now, we're not going to delve deep into that.

256
00:12:53,915 --> 00:12:59,015
For now, let's focus on the animator and how we are going to create transitions.

257
00:12:59,015 --> 00:13:02,305
How are we going to decide when we transition?

258
00:13:02,300 --> 00:13:04,280
This is also very important.

259
00:13:04,280 --> 00:13:11,410
So we are going to create a transition in here by right-clicking on the player idling.

260
00:13:11,405 --> 00:13:18,275
In here we have the make transition and we are going to set it on the player walking.

261
00:13:18,274 --> 00:13:20,464
So let me zoom in a little bit.

262
00:13:20,465 --> 00:13:26,735
So now you can see that we have this arrow going from player idling to play or walking.

263
00:13:26,735 --> 00:13:32,575
And we can also create a transition from the player walking to the player idling.

264
00:13:32,570 --> 00:13:37,000
So now we can go back and forth between these two animations.

265
00:13:36,995 --> 00:13:41,225
Let's click on one of these arrows and look and see what we have here.

266
00:13:41,225 --> 00:13:43,865
So we have something called the exit time.

267
00:13:43,865 --> 00:13:44,995
If you hover over it,

268
00:13:44,990 --> 00:13:48,710
you can see that this transition has a fixed exit time.

269
00:13:48,710 --> 00:13:50,470
What does exit time mean?

270
00:13:50,465 --> 00:13:56,935
It means if I go from the idling to the walking after a certain amount,

271
00:13:56,930 --> 00:14:00,980
do I want to automatically go from the walking to the idling?

272
00:14:00,980 --> 00:14:03,460
And our case, we don't want to do that.

273
00:14:03,455 --> 00:14:07,825
We want to transition back whenever we actually stop walking.

274
00:14:07,820 --> 00:14:11,170
So I'm going to turn off the Has Exit Time.

275
00:14:11,165 --> 00:14:14,965
I'm going to do the same on the way down.

276
00:14:14,960 --> 00:14:19,490
Then we are going to look for the transition duration.

277
00:14:19,490 --> 00:14:21,500
And you can see actually a preview,

278
00:14:21,499 --> 00:14:23,359
a small preview window in here.

279
00:14:23,360 --> 00:14:24,590
So when I play,

280
00:14:24,590 --> 00:14:27,580
I'm idling and then I start walking.

281
00:14:27,575 --> 00:14:29,365
We have the transition duration.

282
00:14:29,360 --> 00:14:33,150
So how do you want to finish the animation

283
00:14:33,154 --> 00:14:37,344
of idling before we transition into walking and our case,

284
00:14:37,340 --> 00:14:39,200
I think we don't need that.

285
00:14:39,200 --> 00:14:43,200
So I'm going to set the transition duration to 0

286
00:14:43,204 --> 00:14:47,734
and also to that in the transition of the walking.

287
00:14:47,735 --> 00:14:49,745
So in both transitions,

288
00:14:49,745 --> 00:14:53,245
both arrows going to and from the walking,

289
00:14:53,240 --> 00:14:55,160
we are going to remove the exit time,

290
00:14:55,160 --> 00:14:58,520
remove the transition later on when we do need them.

291
00:14:58,520 --> 00:15:02,150
I'll make sure to tell you about it. Don't worry.

292
00:15:02,150 --> 00:15:04,550
Now, if we scroll down,

293
00:15:04,550 --> 00:15:07,670
we can see in here that we have something called the conditions.

294
00:15:07,670 --> 00:15:11,410
And this is under which condition do we

295
00:15:11,405 --> 00:15:15,845
transition from the player idling to the player walking?

296
00:15:15,844 --> 00:15:18,864
And under which condition do we transition

297
00:15:18,860 --> 00:15:22,280
from the player walking to the player either link?

298
00:15:22,280 --> 00:15:25,720
So we are going to have to add a condition.

299
00:15:25,715 --> 00:15:29,705
How do we add a condition in here in the transitions?

300
00:15:29,705 --> 00:15:32,185
If we look again to the animator,

301
00:15:32,180 --> 00:15:37,370
we can see that we have the layer step and we have something called the parameters.

302
00:15:37,370 --> 00:15:41,410
And in here we can add certain parameters that we can then

303
00:15:41,405 --> 00:15:45,595
access from our code and make the conditions.

304
00:15:45,590 --> 00:15:49,040
So I'm going to click and tried to add one of the parameters.

305
00:15:49,040 --> 00:15:50,590
You can see that we have float,

306
00:15:50,585 --> 00:15:53,635
integer, Boolean, and a trigger.

307
00:15:53,630 --> 00:15:56,660
Now, float and integer explain themselves.

308
00:15:56,659 --> 00:15:58,009
A Boolean, as you know,

309
00:15:58,010 --> 00:16:03,470
is a true or false and a trigger is just like what the word means, a trigger.

310
00:16:03,470 --> 00:16:06,230
For now, let's focus on the Boolean.

311
00:16:06,230 --> 00:16:08,480
So when I click on the Boolean,

312
00:16:08,480 --> 00:16:11,530
you get the option to call it whatever you want.

313
00:16:11,525 --> 00:16:16,415
So this will be the Boolean that transitions from either link to walking,

314
00:16:16,415 --> 00:16:19,195
I'm going to call it, is.

315
00:16:19,190 --> 00:16:22,090
Walking, hit Enter.

316
00:16:22,085 --> 00:16:25,135
And now you can see that I can turn it on,

317
00:16:25,130 --> 00:16:26,840
which means it becomes true,

318
00:16:26,840 --> 00:16:28,180
or I can turn it off,

319
00:16:28,175 --> 00:16:30,565
which means it becomes false.

320
00:16:30,560 --> 00:16:33,320
So I'm going to click on the transition,

321
00:16:33,320 --> 00:16:36,260
going from player ID link to walking.

322
00:16:36,259 --> 00:16:38,659
And I'm going to click on the condition.

323
00:16:38,660 --> 00:16:41,300
And as you can see, because we only have one parameter,

324
00:16:41,300 --> 00:16:46,450
it immediately thinks that we need the walking or determines which is true.

325
00:16:46,445 --> 00:16:49,535
So when is walking is true,

326
00:16:49,535 --> 00:16:52,775
we transition from player idling too walking.

327
00:16:52,774 --> 00:16:54,704
And if we are walking,

328
00:16:54,699 --> 00:16:56,739
we want to transition to idling.

329
00:16:56,735 --> 00:17:01,225
We want to have a condition where is walking is false.

330
00:17:01,220 --> 00:17:04,120
So now when is walking is true,

331
00:17:04,115 --> 00:17:06,925
we move from player Ivan into play or walking.

332
00:17:06,920 --> 00:17:11,390
When player is walking and is walking becomes false.

333
00:17:11,390 --> 00:17:13,190
We are back at idling.

334
00:17:13,190 --> 00:17:18,220
Let's convert that into code and add behavior to it.

335
00:17:18,215 --> 00:17:21,075
I'm going to open up my script.

336
00:17:21,079 --> 00:17:27,559
And in here the first thing that we need to do is get a reference of the player animator.

337
00:17:27,560 --> 00:17:35,660
So I'm going to create private animator, the player animator.

338
00:17:35,660 --> 00:17:38,320
And he may door.

339
00:17:38,315 --> 00:17:40,645
Now it's private.

340
00:17:40,640 --> 00:17:42,370
How are we going to add?

341
00:17:42,365 --> 00:17:45,335
We can't access it from the inspector in here.

342
00:17:45,335 --> 00:17:47,575
If I click on the dome player on the script,

343
00:17:47,570 --> 00:17:49,070
we don't have access to it.

344
00:17:49,070 --> 00:17:52,990
Well, we can use something called the get component.

345
00:17:52,985 --> 00:18:00,605
So in here I'm going to write player animator is going to be equal to get component.

346
00:18:00,605 --> 00:18:06,235
And we are going to add the component type that we want to get.

347
00:18:06,230 --> 00:18:08,600
So what's happening in here?

348
00:18:08,600 --> 00:18:10,700
Let me hover over the debt component.

349
00:18:10,699 --> 00:18:12,579
It doesn't have an explanation.

350
00:18:12,575 --> 00:18:15,455
I'll tell you what the explanation as you can also go ahead

351
00:18:15,455 --> 00:18:19,045
and find on Unity's documentation, it's very easy.

352
00:18:19,040 --> 00:18:22,640
What it does is as soon as we start,

353
00:18:22,640 --> 00:18:24,910
we get the component,

354
00:18:24,905 --> 00:18:28,285
which is of type animator attached to

355
00:18:28,280 --> 00:18:32,270
the game object that has the player controller as a script.

356
00:18:32,270 --> 00:18:40,660
So effectively what we're doing is this script is using VI get component right here.

357
00:18:40,655 --> 00:18:43,685
And getting the animator,

358
00:18:43,685 --> 00:18:45,095
which is this one.

359
00:18:45,095 --> 00:18:47,515
And now we have a reference to it.

360
00:18:47,510 --> 00:18:51,280
So now we can access many things using this animator.

361
00:18:51,275 --> 00:18:53,215
And you can also go through unit is

362
00:18:53,210 --> 00:18:56,980
documentations and see all the different types of methods,

363
00:18:56,975 --> 00:19:01,825
properties, and various things that we can do with this animator.

364
00:19:01,820 --> 00:19:05,230
So what are we going to do in this animator?

365
00:19:05,225 --> 00:19:07,255
We want to check for a condition.

366
00:19:07,250 --> 00:19:09,550
We want to check if we're walking.

367
00:19:09,545 --> 00:19:15,005
We want to set the Walking to true and then transition into the walking animation.

368
00:19:15,005 --> 00:19:19,885
So I'm going to create an if condition in here and check if

369
00:19:19,880 --> 00:19:26,530
the movement input is different than vector to 0.

370
00:19:26,525 --> 00:19:30,665
So vector to the 0 is just like vector 3 right here.

371
00:19:30,665 --> 00:19:35,485
Dot one, which means 111 vector two dot 0 means 00.

372
00:19:35,480 --> 00:19:39,430
This means if the movement input is not 0,

373
00:19:39,425 --> 00:19:43,315
that means we do have walking right here.

374
00:19:43,310 --> 00:19:46,110
We have velocity, we have movement.

375
00:19:46,114 --> 00:19:49,824
We are going to get the player animator.

376
00:19:49,820 --> 00:19:53,780
We are going to use something called the set Boolean.

377
00:19:53,780 --> 00:19:57,520
And in here you can see that it takes either an ID

378
00:19:57,515 --> 00:20:01,645
or a different way of using the set booth.

379
00:20:01,640 --> 00:20:02,690
If I click on here,

380
00:20:02,690 --> 00:20:05,770
you can see that I can use a string name.

381
00:20:05,765 --> 00:20:07,985
And this is what I'm going to do.

382
00:20:07,985 --> 00:20:10,835
And you can see that we have a string reference.

383
00:20:10,835 --> 00:20:13,225
And what did we say about shrink references?

384
00:20:13,220 --> 00:20:16,330
Whenever we have one, we always go,

385
00:20:16,325 --> 00:20:19,565
we copy it because if there is any mistake,

386
00:20:19,565 --> 00:20:24,545
the IDE will not tell us what the problem is, what the error is.

387
00:20:24,545 --> 00:20:28,645
The IDE, I mean the unity or the Visual Studio.

388
00:20:28,640 --> 00:20:31,350
And in here because we are walking.

389
00:20:31,354 --> 00:20:32,674
Oh, and I forgot.

390
00:20:32,675 --> 00:20:35,495
What does this exclamation mark mean?

391
00:20:35,495 --> 00:20:38,615
What does exclamation mark equals mean?

392
00:20:38,615 --> 00:20:41,065
So if you see right here,

393
00:20:41,060 --> 00:20:46,070
we've said that when mouse positions of x is less than this green point,

394
00:20:46,070 --> 00:20:51,700
we could have said that if the mouse position that AX is equal,

395
00:20:51,695 --> 00:20:54,205
whenever we want to compare two values,

396
00:20:54,200 --> 00:20:56,440
we can set them as equal, equal.

397
00:20:56,435 --> 00:21:03,055
That means is the most position x the same as the mouse point dot x.

398
00:21:03,050 --> 00:21:07,300
But in here we decided to keep it as less than or equal.

399
00:21:07,295 --> 00:21:09,025
But what if we want to say,

400
00:21:09,020 --> 00:21:10,810
if it's not equal?

401
00:21:10,805 --> 00:21:14,295
Well, then we use the exclamation mark equals.

402
00:21:14,299 --> 00:21:20,559
This means that whenever movement input is different than the vector two dot 0,

403
00:21:20,555 --> 00:21:24,095
we have the is walking set to true.

404
00:21:24,095 --> 00:21:25,285
Else.

405
00:21:25,280 --> 00:21:29,920
That means when the movement input is equal to 0,

406
00:21:29,915 --> 00:21:32,515
we are going to duplicate this line.

407
00:21:32,510 --> 00:21:35,900
And if we hold down Alt and use the arrow keys,

408
00:21:35,900 --> 00:21:37,930
we can put it in here.

409
00:21:37,925 --> 00:21:44,605
And we are going to set the is walking to false. We'll save that.

410
00:21:44,600 --> 00:21:47,900
Let's go over this one more time because I forgot to tell you

411
00:21:47,900 --> 00:21:51,410
about this and just kept on using it, which is very bad.

412
00:21:51,410 --> 00:21:54,080
So I hope that wasn't too confusing.

413
00:21:54,080 --> 00:21:58,130
Anyways, we create an if condition that we learned in a previous video.

414
00:21:58,130 --> 00:22:03,710
We check if the movement speed is different than a vector 0,

415
00:22:03,710 --> 00:22:07,610
say different than using an exclamation mark and equal.

416
00:22:07,610 --> 00:22:10,310
So if movement speed is different than 0,

417
00:22:10,310 --> 00:22:12,040
that means we are walking.

418
00:22:12,035 --> 00:22:18,215
We are going to access the player animator who are going to use the set Bool method.

419
00:22:18,215 --> 00:22:25,265
And we are going to access the is walking parameter and be setting it to true.

420
00:22:25,265 --> 00:22:27,875
And remember, when we set it to true,

421
00:22:27,875 --> 00:22:31,885
we have the transition in here that says if B is walking is true,

422
00:22:31,880 --> 00:22:34,240
we go from idling too walking,

423
00:22:34,235 --> 00:22:37,055
and we've done the same using an else.

424
00:22:37,055 --> 00:22:41,275
Else means when movement input is equal to vector 2,

425
00:22:41,270 --> 00:22:45,200
2, 0, that means we stopped walking is working as false.

426
00:22:45,200 --> 00:22:48,340
We go from player walking to play or idling.

427
00:22:48,335 --> 00:22:50,405
Let's see if that works.

428
00:22:50,405 --> 00:22:51,985
So we start the game.

429
00:22:51,980 --> 00:22:55,280
We can see right here that we have player idling.

430
00:22:55,279 --> 00:22:58,009
If we start walking, there you go.

431
00:22:58,010 --> 00:23:01,720
You can see that now we are walking and it's evident by the way,

432
00:23:01,715 --> 00:23:04,985
the legs of our player are moving.

433
00:23:04,985 --> 00:23:06,565
How cool is that?

434
00:23:06,560 --> 00:23:08,780
So now we have animations.

435
00:23:08,780 --> 00:23:12,080
We have transitions from one animation to the other.

436
00:23:12,080 --> 00:23:13,790
We've created two animations.

437
00:23:13,790 --> 00:23:16,400
Maybe you've created the third one on yourself.

438
00:23:16,400 --> 00:23:17,830
I'll not do it right now,

439
00:23:17,825 --> 00:23:21,905
although it later on for future Michel to handle that problem,

440
00:23:21,905 --> 00:23:23,645
I feel lazy right now.

441
00:23:23,645 --> 00:23:26,695
But there is one more thing that we need to take care

442
00:23:26,690 --> 00:23:30,190
of if we go right here and to the dome player.

443
00:23:30,185 --> 00:23:32,585
And let's go to Animations.

444
00:23:32,585 --> 00:23:34,135
If we choose the idling,

445
00:23:34,130 --> 00:23:36,590
for example, and we play it,

446
00:23:36,590 --> 00:23:39,310
you'll notice that we have our gun and

447
00:23:39,305 --> 00:23:43,115
our arm standing still right there not doing anything.

448
00:23:43,115 --> 00:23:44,755
This is not good at all.

449
00:23:44,750 --> 00:23:47,630
It makes the game look very, very bad.

450
00:23:47,630 --> 00:23:50,440
So, and also when it comes to the walking,

451
00:23:50,435 --> 00:23:52,795
so you can see right here that the arm is moving,

452
00:23:52,790 --> 00:23:53,810
the player is moving,

453
00:23:53,810 --> 00:23:57,520
but the arm and gone are very rigid.

454
00:23:57,515 --> 00:23:58,765
In the next video,

455
00:23:58,760 --> 00:24:00,590
we are going to be fixing that.

456
00:24:00,590 --> 00:24:02,650
So before I go,

457
00:24:02,645 --> 00:24:06,305
make sure to stage everything,

458
00:24:06,305 --> 00:24:12,805
make sure to commit added and animations to

459
00:24:12,800 --> 00:24:17,840
the idling and walking in your case also

460
00:24:17,840 --> 00:24:23,900
the torpedo animation to the player, commit the changes.

461
00:24:23,900 --> 00:24:28,140
And I'll see you in the next video.

