1
00:00:12,325 --> 00:00:15,900
OK. Hi everyone. Welcome back to this tutorial

2
00:00:15,900 --> 00:00:19,375
OK, let's go back to the Unreal Engine 4 Editor

3
00:00:19,375 --> 00:00:22,325
Let's review what we made in the last lesson first

4
00:00:22,325 --> 00:00:25,275
We have implemented AI basic turning in the last lesson

5
00:00:25,275 --> 00:00:30,375
Now our AI will turn to wherever player goes

6
00:00:30,375 --> 00:00:32,300
This is a simple mechanism

7
00:00:32,300 --> 00:00:34,806
In this lesson, we will create another mechanism

8
00:00:34,831 --> 00:00:37,450
That is, when seeing the player drawing a sword

9
00:00:37,450 --> 00:00:43,550
The AI is told to get ready to fight

10
00:00:43,550 --> 00:00:45,375
This is rather simple

11
00:00:45,375 --> 00:00:46,850
Now I find a problem

12
00:00:46,850 --> 00:00:54,125
That is, as soon as our camera moves to our AI's body

13
00:00:54,125 --> 00:00:56,200
It makes a collision

14
00:00:56,200 --> 00:00:58,975
For example, flashing like this

15
00:00:58,975 --> 00:01:01,025
This is due to the collision

16
00:01:01,025 --> 00:01:06,525
Our camera arm is about five meters

17
00:01:06,525 --> 00:01:09,350
so the body of AI will be captured

18
00:01:09,350 --> 00:01:11,850
and there will be a collision

19
00:01:11,850 --> 00:01:14,475
Now I want to modify this object

20
00:01:14,475 --> 00:01:20,600
Sometimes our camera arm also collides with our player

21
00:01:20,600 --> 00:01:23,100
We can modify it here

22
00:01:23,100 --> 00:01:27,625
Click the Collision Presents here and set it to Custom

23
00:01:27,625 --> 00:01:30,525
Then turn off the Camera

24
00:01:30,660 --> 00:01:35,935
Similarly, select the Camera and set it as Not

25
00:01:35,975 --> 00:01:40,300
Then let's find our AI and apply the same setting

26
00:01:40,325 --> 00:01:44,200
Because our camera will collide with the objects

27
00:01:44,200 --> 00:01:47,600
Just turn off the Camera and ignore it

28
00:01:47,600 --> 00:01:48,850
Now let's have a try

29
00:01:48,850 --> 00:01:50,200
Draw the sword

30
00:01:50,225 --> 00:01:51,240
OK

31
00:01:51,550 --> 00:01:53,375
Now there is no problem

32
00:01:53,375 --> 00:01:55,800
There is no problem when the base role attacks

33
00:01:55,800 --> 00:01:57,975
and when the camera goes back here

34
00:01:57,975 --> 00:01:59,450
OK

35
00:01:59,450 --> 00:02:01,625
OK, we have realized this simple function

36
00:02:01,625 --> 00:02:03,100
Now let's implement another one

37
00:02:03,100 --> 00:02:06,550
which is to create a Animation Blueprints for AI

38
00:02:06,550 --> 00:02:09,425
so that it will have an animation just like the player

39
00:02:09,425 --> 00:02:13,150
Otherwise it will be strange to keep it in this T-Pose

40
00:02:13,150 --> 00:02:16,225
Now let's go back to the Content Browser

41
00:02:16,225 --> 00:02:18,650
Find the Animation Blueprints of character

42
00:02:18,650 --> 00:02:24,159
AI blueprint is copied from the character blueprint

43
00:02:24,183 --> 00:02:26,400
in order to animate it

44
00:02:26,400 --> 00:02:28,800
OK, let's open this Animation Blueprint

45
00:02:28,800 --> 00:02:30,425
Put it here

46
00:02:30,600 --> 00:02:33,875
Let's see which variables to apply

47
00:02:33,875 --> 00:02:37,200
Actually we only need to use two variables

48
00:02:37,225 --> 00:02:39,600
from the character's blueprint

49
00:02:39,600 --> 00:02:42,125
So when we switch to the AI later

50
00:02:42,125 --> 00:02:44,625
we only need to create two variables

51
00:02:44,625 --> 00:02:46,850
The first is Equip

52
00:02:46,850 --> 00:02:53,075
This boolean tells our AI whether the sword is equipped or not

53
00:02:53,075 --> 00:02:55,900
The other is Defense

54
00:02:55,900 --> 00:02:58,525
Because our AI also needs defense

55
00:02:58,725 --> 00:03:01,725
OK, let's switch to our browser

56
00:03:01,725 --> 00:03:05,525
Then let's copy

57
00:03:05,525 --> 00:03:07,825
Click on the Copy here

58
00:03:07,825 --> 00:03:10,550
Certainly, we can't follow the previous name

59
00:03:10,550 --> 00:03:14,550
Let's name it as BPA_NegativeAI

60
00:03:14,550 --> 00:03:19,150
Let's move this to the AI folder

61
00:03:19,150 --> 00:03:22,150
If you don't have these in the left

62
00:03:22,150 --> 00:03:24,325
You can click this switch here

63
00:03:24,325 --> 00:03:27,425
Then move it into this AI

64
00:03:27,425 --> 00:03:30,950
Then open the AI folder and find this

65
00:03:31,231 --> 00:03:39,050
We can delete these because they read from the player

66
00:03:39,050 --> 00:03:43,100
Now this blueprint is to be used on AI

67
00:03:43,100 --> 00:03:46,425
so we can no longer call variables from the player

68
00:03:46,425 --> 00:03:48,875
We need to call variables from the AI itself

69
00:03:48,875 --> 00:03:50,775
cast to bp

70
00:03:50,775 --> 00:03:53,375
Select this NegativeAI

71
00:03:53,375 --> 00:03:57,400
Let's put it here and then connect it to here

72
00:03:57,450 --> 00:04:00,350
OK. Then organize them

73
00:04:00,350 --> 00:04:04,775
Then get equip

74
00:04:04,775 --> 00:04:07,800
Then get defense

75
00:04:07,800 --> 00:04:10,000
Get these two

76
00:04:10,000 --> 00:04:12,525
OK, it's almost done

77
00:04:12,525 --> 00:04:18,350
Let's put this Reset Attack Montage aside

78
00:04:18,350 --> 00:04:19,500
OK

79
00:04:19,500 --> 00:04:21,975
Then let's go back to the AI

80
00:04:21,975 --> 00:04:25,550
Then apply the Animation Blueprint we created for it

81
00:04:25,775 --> 00:04:29,350
We have named it BPA_NegativeAI

82
00:04:29,350 --> 00:04:30,575
Let's go back

83
00:04:30,575 --> 00:04:35,350
Now you can find that our AI can turn towards our player

84
00:04:35,350 --> 00:04:41,625
and its static animation has also been done

85
00:04:41,625 --> 00:04:44,180
Now we need to implement another function

86
00:04:44,205 --> 00:04:50,125
That is to use a Blueprint Interface to communicate with AI

87
00:04:50,125 --> 00:04:51,670
Tell the AI that

88
00:04:51,694 --> 00:04:55,050
we are ready to fight

89
00:04:55,050 --> 00:04:57,750
Now let's go back to the Content Browser

90
00:04:57,750 --> 00:05:00,050
Let's create a new folder here

91
00:05:00,050 --> 00:05:05,000
Name it BP_WorldSetting

92
00:05:05,025 --> 00:05:10,250
Put all relevant blueprints in here

93
00:05:10,275 --> 00:05:12,000
We may use it less frequent

94
00:05:12,000 --> 00:05:14,825
Let's put the Blueprint Interface into it first

95
00:05:14,825 --> 00:05:17,400
It's not created from the Blueprint Class here

96
00:05:17,400 --> 00:05:21,925
We can find it in the Blueprints under Create Advanced Asset

97
00:05:21,925 --> 00:05:23,525
Find Blueprint Interface

98
00:05:23,525 --> 00:05:26,375
Name it with the BPI prefix

99
00:05:26,375 --> 00:05:30,225
It's the abbreviation of Blueprint Interface

100
00:05:30,225 --> 00:05:33,725
So I like to name it with the BPI prefix

101
00:05:33,725 --> 00:05:36,975
Please remember this prefix, it's very important

102
00:05:36,975 --> 00:05:40,525
because there are hundreds types of blueprint interfaces

103
00:05:40,525 --> 00:05:44,625
With this prefix, we can find it directly

104
00:05:44,625 --> 00:05:48,100
Let's name it ReadyToFight

105
00:05:49,300 --> 00:05:53,700
After we open it, we can see a new function here

106
00:05:53,700 --> 00:05:57,575
This new function is the event we call

107
00:05:57,575 --> 00:05:59,925
Let's name it Ready

108
00:05:59,925 --> 00:06:00,925
OK

109
00:06:01,000 --> 00:06:03,775
Then let's compile

110
00:06:03,775 --> 00:06:10,100
OK. Then let's focus on the player

111
00:06:10,100 --> 00:06:14,300
Then how to use the Blueprint Interface we created on the player

112
00:06:14,300 --> 00:06:18,675
First, click on the Class Setup here

113
00:06:18,675 --> 00:06:22,725
In it, we can change the Parent Class

114
00:06:22,725 --> 00:06:26,050
And customize these blueprint options

115
00:06:26,050 --> 00:06:28,875
We need to find the interface

116
00:06:28,875 --> 00:06:32,475
Then you can find that there is zero implemented interface

117
00:06:32,475 --> 00:06:34,450
Click the Add here

118
00:06:34,450 --> 00:06:39,525
Here are actually 49 options to select from

119
00:06:39,525 --> 00:06:43,475
Search for bpi, the prefix we used in here

120
00:06:43,475 --> 00:06:46,205
Select this Ready to Fight. Then it's added directly

121
00:06:46,525 --> 00:06:47,875
OK

122
00:06:47,875 --> 00:06:53,100
Let's compile it again

123
00:06:53,100 --> 00:06:55,689
Use this Blueprint Interface

124
00:06:55,713 --> 00:06:57,500
when the player drawing the sword

125
00:06:57,500 --> 00:06:59,425
Go back to the Equip here

126
00:06:59,875 --> 00:07:02,725
After the player drawing the sword

127
00:07:02,725 --> 00:07:04,650
we're going to make a call here

128
00:07:04,650 --> 00:07:08,475
Enter bpi and close the Context Sensitive

129
00:07:08,475 --> 00:07:13,850
It is suffixed by Message when we conveying message

130
00:07:13,950 --> 00:07:21,250
The Target is what we want to convey the message to

131
00:07:21,250 --> 00:07:29,275
Get the AI variable that we have instanced and put it here

132
00:07:29,275 --> 00:07:32,850
It's like telling it that we're ready

133
00:07:32,850 --> 00:07:37,100
Let's go back to the AI, it has Class Setup option

134
00:07:37,375 --> 00:07:41,050
Just like the character

135
00:07:41,050 --> 00:07:44,350
we need to add blueprint interface

136
00:07:44,350 --> 00:07:48,825
Add BPI Ready to Fight

137
00:07:48,825 --> 00:07:49,967
OK

138
00:07:50,150 --> 00:07:55,275
Then how to receive the message from the player

139
00:07:55,275 --> 00:07:59,675
Search ready to fight here

140
00:07:59,825 --> 00:08:03,625
Add an Event Ready

141
00:08:03,625 --> 00:08:08,350
to receive the message from the player

142
00:08:08,425 --> 00:08:11,850
Then tick this

143
00:08:11,850 --> 00:08:15,725
then enter montage

144
00:08:15,725 --> 00:08:18,250
Turn off Context Sensitive

145
00:08:19,194 --> 00:08:21,325
Here is Montage Play

146
00:08:21,780 --> 00:08:28,650
Then Get Anim Instance, Mesh

147
00:08:28,675 --> 00:08:31,600
As for the Asset, let's go back to the base role

148
00:08:31,600 --> 00:08:37,675
AI and player has the same sword-drawing animation

149
00:08:37,675 --> 00:08:40,675
Let's get it and apply it on the AI

150
00:08:40,675 --> 00:08:44,050
OK, the basic function is done

151
00:08:44,050 --> 00:08:45,650
Let's compile it

152
00:08:45,650 --> 00:08:50,450
After the player drawing the sword, the AI also draws the sword

153
00:08:50,450 --> 00:08:52,600
But the AI draws rather slow

154
00:08:52,600 --> 00:08:57,350
Go back to the player and add a Sequence here

155
00:08:57,350 --> 00:09:01,100
Let it delay about 1 second

156
00:09:01,100 --> 00:09:03,325
and then tell AI to draw the sword

157
00:09:03,325 --> 00:09:05,050
Otherwise 2.5 seconds is a bit slow

158
00:09:05,050 --> 00:09:07,125
Let's add a Delay. OK

159
00:09:07,125 --> 00:09:15,725
Place these boolean value in front

160
00:09:15,725 --> 00:09:18,000
and keep these ones here

161
00:09:18,050 --> 00:09:19,450
Now let's have a try

162
00:09:20,400 --> 00:09:22,675
OK, see, it moves faster

163
00:09:22,850 --> 00:09:25,475
Now it's ready to fight

164
00:09:25,475 --> 00:09:26,550
OK

165
00:09:26,550 --> 00:09:29,175
Then what we need to realize is

166
00:09:29,175 --> 00:09:32,650
for example, after the player drawing the sword

167
00:09:32,675 --> 00:09:35,225
the AI will get ready to fight

168
00:09:35,225 --> 00:09:38,525
the AI will start to follow our player

169
00:09:38,525 --> 00:09:41,200
OK, let's start to produce

170
00:09:41,200 --> 00:09:47,300
Let's return to the AI Behavior Tree

171
00:09:47,300 --> 00:09:50,300
Turn off those redundant projects

172
00:09:50,600 --> 00:09:52,900
Let's return to our AI behavior tree

173
00:09:52,900 --> 00:09:55,000
It's here

174
00:09:55,300 --> 00:09:59,075
We need to create a new bool key named ReadyToFight

175
00:09:59,075 --> 00:10:05,100
I think you should know, as we have covered in previous lessons

176
00:10:05,100 --> 00:10:08,925
that our AI Behavior Tree cannot read

177
00:10:08,925 --> 00:10:11,875
the values in the character's blueprint

178
00:10:11,875 --> 00:10:14,225
But the values in our character's blueprint can set

179
00:10:14,225 --> 00:10:17,200
the values of Blackboard in Behavior Tree

180
00:10:17,225 --> 00:10:18,625
You should know this

181
00:10:18,625 --> 00:10:21,917
And the AI Behavior Tree can only call the values in Blackboard

182
00:10:21,942 --> 00:10:23,850
OK, now let's return to our AI

183
00:10:23,850 --> 00:10:26,775
We need to read the blackboard here

184
00:10:26,775 --> 00:10:28,700
Similar to this

185
00:10:28,700 --> 00:10:31,075
Get Blackboard

186
00:10:31,075 --> 00:10:38,913
and then set the blackboard value as bool

187
00:10:39,248 --> 00:10:41,018
Link bool with Montage Play

188
00:10:41,725 --> 00:10:44,825
Then tick Bool Value

189
00:10:44,825 --> 00:10:47,500
Then Create Literal Name

190
00:10:47,500 --> 00:10:49,450
Name it as ReadyToFight

191
00:10:49,450 --> 00:10:51,600
OK. Then

192
00:10:53,725 --> 00:10:56,275
OK, finished

193
00:10:56,275 --> 00:10:58,375
Then when this bool value is ticked

194
00:10:58,375 --> 00:11:01,600
The AI will be told to fight

195
00:11:01,600 --> 00:11:03,925
Then let's go back to the AI Behavior Tree

196
00:11:04,059 --> 00:11:12,350
Here let's put these two in one event

197
00:11:12,350 --> 00:11:16,525
Then let's create a new Sequence here

198
00:11:16,525 --> 00:11:20,975
As I told you before, the function of Selector is

199
00:11:20,975 --> 00:11:23,711
if the first one is selected, the second one won't

200
00:11:23,736 --> 00:11:25,700
and vice versa

201
00:11:25,775 --> 00:11:27,875
Now it's like choosing one from two

202
00:11:27,875 --> 00:11:30,925
Judge whether the first thing can be executed

203
00:11:30,925 --> 00:11:37,500
If it can be executed, then the second won't be executed

204
00:11:37,500 --> 00:11:40,675
Execute the second when the first can't be executed

205
00:11:40,675 --> 00:11:44,500
Then Add Decorator on this Composite Node

206
00:11:44,500 --> 00:11:48,150
I may have said it before the last lesson

207
00:11:48,150 --> 00:11:51,350
that the Decorator is used to judge the values

208
00:11:51,350 --> 00:11:54,800
Then let's get the value of ReadyToFight first

209
00:11:54,800 --> 00:11:58,975
If this value is true, we execute the following

210
00:11:58,975 --> 00:12:02,200
If this value is false, we execute the stuff here

211
00:12:02,200 --> 00:12:04,925
Here we can name it Focus

212
00:12:05,625 --> 00:12:06,825
OK

213
00:12:07,625 --> 00:12:12,125
These two are completely independent events

214
00:12:12,125 --> 00:12:19,075
If this is true, the AI starts to move to our character

215
00:12:19,075 --> 00:12:20,825
Use Move To

216
00:12:20,825 --> 00:12:28,725
As for Move To, we may choose not only vectors

217
00:12:28,725 --> 00:12:31,425
but also blueprints

218
00:12:31,425 --> 00:12:35,150
We can directly select the corresponding blueprint to move to

219
00:12:35,150 --> 00:12:36,336
But as you can see

220
00:12:36,360 --> 00:12:39,925
we can't select the Target we created from here

221
00:12:39,925 --> 00:12:42,074
So we need to return to the Blackboard

222
00:12:42,099 --> 00:12:44,250
Turn on the Key Type in Target

223
00:12:44,250 --> 00:12:48,900
And the base class should be Actor

224
00:12:48,975 --> 00:12:53,750
OK, now we can select the Target here

225
00:12:53,750 --> 00:12:56,250
OK, now let's try it

226
00:12:57,150 --> 00:12:59,775
The player draws the sword

227
00:13:01,550 --> 00:13:04,325
Now the AI starts to move

228
00:13:04,325 --> 00:13:08,600
But it moves so fast

229
00:13:08,600 --> 00:13:10,800
A bit too fast, we can modify it here

230
00:13:10,900 --> 00:13:12,950
Set Max Walk Speed

231
00:13:12,950 --> 00:13:16,300
Let's set it to 150

232
00:13:16,300 --> 00:13:21,475
Then let's delay the play

233
00:13:21,475 --> 00:13:23,700
Let's see how many seconds to set

234
00:13:24,925 --> 00:13:27,925
It's duration is 2.6

235
00:13:27,925 --> 00:13:31,975
Actually, I think 2 seconds is OK

236
00:13:31,975 --> 00:13:33,725
Let's set it to 2

237
00:13:34,350 --> 00:13:38,850
We have set the Max Walk Speed to 150

238
00:13:38,850 --> 00:13:40,575
Let's set it to 125

239
00:13:40,575 --> 00:13:43,575
No, set it to 150, since its body is big

240
00:13:43,575 --> 00:13:45,100
Let's try again

241
00:13:45,100 --> 00:13:46,225
OK

242
00:13:46,225 --> 00:13:48,000
The player draws the sword

243
00:13:48,000 --> 00:13:49,500
Then the AI

244
00:13:49,500 --> 00:13:50,875
Why it doesn't move

245
00:13:50,875 --> 00:13:52,250
OK, now it moves

246
00:13:52,250 --> 00:13:55,625
But now it walks slower than before

247
00:13:55,625 --> 00:13:57,185
Then you will find it doesn't move

248
00:13:57,209 --> 00:13:58,725
after reaching to a certain place

249
00:13:58,725 --> 00:14:00,250
That is a problem

250
00:14:00,250 --> 00:14:01,700
Let's return to here

251
00:14:01,700 --> 00:14:04,100
We didn't enlarge it before

252
00:14:04,100 --> 00:14:07,850
Now we need to scale up the Nav mesh

253
00:14:07,850 --> 00:14:14,250
Let's enlarge it so that to cover the entire map

254
00:14:14,467 --> 00:14:15,842
Place it here

255
00:14:18,075 --> 00:14:19,975
Move it to the center

256
00:14:20,400 --> 00:14:22,700
Enlarge it to cover the entire map

257
00:14:22,700 --> 00:14:24,425
Now let's try it again

258
00:14:25,675 --> 00:14:26,725
OK

259
00:14:26,900 --> 00:14:31,775
OK, now the AI follows the player to move

260
00:14:32,275 --> 00:14:36,050
OK, we have completed this function in this lesson

261
00:14:36,050 --> 00:14:38,450
In the next lesson, we will create this

262
00:14:38,450 --> 00:14:44,325
when the AI moves near the player, it attacks and rolls

263
00:14:44,325 --> 00:14:46,325
Just like the player

264
00:14:46,325 --> 00:14:50,325
it can attack and defend

265
00:14:50,325 --> 00:14:52,975
So in the next lesson we will mainly introduce

266
00:14:52,975 --> 00:14:55,775
the attacks and rolls of the AI

267
00:14:55,775 --> 00:14:58,875
OK, so that's all for this lesson

268
00:14:58,875 --> 00:15:00,825
OK, see you in the next lesson


