WEBVTT

00:06.820 --> 00:08.050
Welcome back.

00:08.140 --> 00:10.000
Now we have some basic behavior.

00:10.000 --> 00:15.970
We still have a ways to go, but we know that our melee attackers will continue walking in closer.

00:15.970 --> 00:18.730
And as soon as they get here, they attack.

00:18.760 --> 00:26.260
Now, I'd like them to attack and then kind of shuffle around or move around to a different location

00:26.260 --> 00:28.750
around their target aura.

00:28.900 --> 00:34.170
So that way they don't just stand there in one location and just swing away and swing away.

00:34.180 --> 00:39.880
If they swing, then I'd like them to move around over to here and swing and move around over to here

00:39.880 --> 00:40.660
and swing.

00:40.660 --> 00:42.340
And I'd like that to be random.

00:42.340 --> 00:44.890
So that's what we're going to take care of in this video.

00:45.040 --> 00:49.330
Now, another thing, if we press play, take a look at the melee attacker.

00:49.330 --> 00:52.680
As soon as it reaches that point, there's a little pause.

00:52.690 --> 00:58.810
That point is 500 units away because they're in this branch move to Target.

00:58.810 --> 01:05.650
But as soon as they're no longer far enough to be approaching using this branch, then am I close enough

01:05.650 --> 01:06.310
to attack?

01:06.340 --> 01:07.580
Is suddenly true.

01:07.580 --> 01:13.040
And then they're using this move to get close and there's a little bit of a jerk.

01:13.040 --> 01:14.720
It's very slight.

01:14.720 --> 01:19.460
It's hardly noticeable, but you can see that he kind of jerks a little bit.

01:19.580 --> 01:21.260
Now that can be fixed.

01:21.290 --> 01:23.660
We can take a look at his blend space.

01:23.660 --> 01:28.370
So I'd like to really quickly just take a look at that before moving on.

01:28.610 --> 01:38.990
So we have blueprints and character and we can go to Goblin Spear and in AVP, Goblin Spear, we can

01:38.990 --> 01:45.920
take a look in the asset override to see where it's idle walk, run, blend space is.

01:45.920 --> 01:46.580
It's here.

01:46.580 --> 01:48.230
We can browse to that and here it is.

01:48.230 --> 01:50.360
It's in its animations sphere.

01:50.360 --> 01:54.140
I'm going to go into this and change the blend settings just a bit.

01:54.170 --> 02:03.350
Now the blend space uses a weight speed and this is kind of an interesting way to handle this, but

02:03.350 --> 02:07.670
it's basically the speed at which the sample weights are allowed to change.

02:07.670 --> 02:14.900
So in other words, if we change this value, we can make that jerkiness a little less jerky, a little

02:14.900 --> 02:15.830
smoother.

02:15.980 --> 02:21.290
Now we see that a speed of one means the sample weight can change from 0 to 1 in one second.

02:21.320 --> 02:23.870
A speed of two means that this would take half a second.

02:23.870 --> 02:29.300
So the higher the value, the faster we're going to blend between our sample weights.

02:29.300 --> 02:32.270
That's those inputs for that blend space.

02:32.270 --> 02:36.800
So if I put a value of four, then it'll take a quarter second.

02:37.210 --> 02:39.040
And we should see that jerkiness.

02:39.070 --> 02:40.480
Be a little smoother.

02:42.320 --> 02:44.120
In fact, there is no jerkiness.

02:44.120 --> 02:45.500
There's a slight pause.

02:45.530 --> 02:46.940
I'm okay with a slight pause.

02:46.940 --> 02:48.020
I'm fine with that.

02:48.020 --> 02:49.880
I just don't want jerkiness.

02:50.760 --> 02:52.110
So that looks great.

02:52.110 --> 02:56.460
And I think a value of four for weight speed is perfect.

02:56.490 --> 03:00.570
We can even add that for our slingshot goblin.

03:00.600 --> 03:05.500
That way, if they ever stop and start again, they don't do so jerkily.

03:05.520 --> 03:07.500
So I'm going to go ahead and close out of those.

03:07.530 --> 03:09.110
That takes care of those.

03:09.120 --> 03:12.570
But now for this, finding a new location business.

03:12.570 --> 03:19.520
So when my melee attackers get close and attack, I want them to attack and then find a new location.

03:19.530 --> 03:24.720
And this on screen debug message here is going to be quite annoying.

03:24.720 --> 03:32.730
So what I can do is just go into my Bet service, find nearest player and we can take away that on screen

03:32.730 --> 03:33.810
debug message here.

03:33.810 --> 03:35.560
We don't need that anymore do we?

03:35.580 --> 03:38.340
So next time we compile that will be gone.

03:38.640 --> 03:40.890
Now back to the task at hand.

03:40.890 --> 03:42.290
We need a task, right?

03:42.300 --> 03:44.430
We need a behavior tree task.

03:44.460 --> 03:48.690
We want one for finding a new location around the player.

03:48.720 --> 03:50.860
Now, this is a simple task.

03:50.860 --> 03:54.130
No need to go through the trouble of making one in C plus plus.

03:54.160 --> 03:57.520
Now that we know how to do that, that's an option.

03:57.520 --> 04:04.930
I'm going to make it in blueprint and I'm going to have a new blackboard key for a location for our

04:04.930 --> 04:09.130
AI to move to that's going to be different than Target to follow.

04:09.130 --> 04:09.670
Right?

04:09.670 --> 04:14.020
Because if they're moving to their target to follow, they're moving towards aura.

04:14.020 --> 04:19.210
And as soon as they reach it and attack, I want to find a new location that's different than the target

04:19.210 --> 04:20.080
to follow.

04:20.110 --> 04:25.390
I want a vector location somewhere in the vicinity around Aura.

04:25.420 --> 04:27.580
So I'm going to add a new blackboard key.

04:27.610 --> 04:34.180
We're going to go to Blackboard, add new Key, and we're going to use a vector and I'm going to call

04:34.180 --> 04:41.170
this vector move to location and we're going to set that move to location with a task here.

04:41.170 --> 04:43.840
So I'm going to make a new behavior tree task.

04:43.840 --> 04:49.150
So I'm going to click the dropdown for new task and we can choose one of our tasks.

04:49.180 --> 04:55.090
BT Attack is the Blueprint version and BT task attack is the C plus plus version.

04:55.090 --> 04:58.990
Notice it shows the full C plus plus name minus the U.

04:58.990 --> 05:01.630
And then we have BT Task Blueprint Base.

05:01.630 --> 05:06.490
That's what I'm going to choose and we're going to choose to save it here in our AI folder.

05:06.490 --> 05:08.580
And I'm going to call this BT.

05:09.190 --> 05:16.240
I'm going to use the convention BT without the full task to signify that this is a blueprint task and

05:16.240 --> 05:20.980
I'm going to call this BT go around Target.

05:20.980 --> 05:27.400
So I'm going to go ahead and save it there and here in BT, go around Target, I'm going to use event,

05:27.400 --> 05:33.100
receive, execute AI and we're also going to need to call, finish, execute.

05:33.850 --> 05:37.570
And in between here is where we're going to make things happen.

05:37.570 --> 05:41.920
Now I'm going to want a blackboard key selector so that I can set its value.

05:41.950 --> 05:46.000
We're going to want to set that value for move to location.

05:46.000 --> 05:53.980
So here in BT, go around Target, I'm going to add a new variable and change its type to blackboard.

05:54.580 --> 06:04.870
Key selector, and I'm going to call this new location and we can link this up with our move to location

06:04.870 --> 06:05.550
here.

06:05.560 --> 06:13.330
If we drag off of this and add the task, the task is go around target and if we click on it and select

06:13.330 --> 06:13.750
it.

06:14.280 --> 06:15.630
We can set it here now.

06:15.630 --> 06:16.830
We don't see it yet.

06:16.860 --> 06:20.730
We have to go back and open the eye icon and compile.

06:21.060 --> 06:26.520
And once we do that, we can go back to our behavior tree and see new location and we can link it up

06:26.520 --> 06:28.440
with our move to location here.

06:28.560 --> 06:35.100
Once we've done that here in go around Target, we can set the value of new location.

06:35.220 --> 06:38.520
So how do we set the value of new location?

06:38.520 --> 06:45.480
Well, we're going to need to find a new location around our enemies Target.

06:45.510 --> 06:49.050
Now, the enemy doesn't know what its target is.

06:49.050 --> 06:50.490
Exactly, does it?

06:50.520 --> 06:51.990
Well, it kind of does.

06:51.990 --> 06:55.060
It has a target to follow, which is an object.

06:55.080 --> 07:00.590
So that's another thing that we can sort of link up with one of our blackboard keys.

07:00.600 --> 07:05.150
We can have a new blackboard key selector for the target.

07:05.160 --> 07:08.970
So I'm going to add a new blackboard key selector called Target.

07:09.120 --> 07:11.730
I'm going to open the eye icon compile.

07:11.730 --> 07:19.780
And in our go around target task node, I'm going to set target to be linked up with target to follow.

07:19.780 --> 07:25.690
Now we have access to target to follow here in our task and it's a good idea to make sure that that's

07:25.690 --> 07:27.070
a valid target.

07:27.190 --> 07:30.640
So what we can do is get our target blackboard key selector.

07:30.670 --> 07:40.090
We can get the value of that blackboard key selector by using get blackboard value as and we can choose,

07:40.090 --> 07:43.030
we can choose actor, we can choose object.

07:43.030 --> 07:49.210
And we know if we go into our blackboard and select target to follow that its base class is actor.

07:49.210 --> 07:52.870
So get blackboard value as actor makes sense.

07:53.560 --> 07:57.220
So we're going to use get Blackboard value as actor.

07:57.250 --> 08:02.950
We're going to get that return value which is an actor and I'd like to use is valid to make sure that

08:02.950 --> 08:04.750
it is indeed valid.

08:05.220 --> 08:07.170
So this should be aura, right?

08:07.170 --> 08:14.640
And as soon as we have aura, if it's valid, we can get auras location with get actor location.

08:17.610 --> 08:19.020
What are we going to do with that?

08:19.020 --> 08:25.710
Well, we want to find a new location that's somewhere around Ora's actor location.

08:25.710 --> 08:29.340
But we want this new location to be navigable.

08:29.340 --> 08:33.030
We want it to be a reachable point in our nav mesh.

08:33.030 --> 08:38.610
We don't want to try to get any random location that could be in some hole in the nav mesh.

08:38.610 --> 08:39.090
Right?

08:39.090 --> 08:41.820
If I press P and look at our nav mesh.

08:42.470 --> 08:44.310
Let's say we're close to this pillar.

08:44.330 --> 08:48.880
We don't want a random location that could be somewhere in this hole.

08:48.890 --> 08:56.330
We want it to be a navigable point, which means it's in the green area somewhere we can actually reach.

08:56.540 --> 09:00.710
So the way we can do that is with the function.

09:00.710 --> 09:06.170
Get random location in navigable radius.

09:06.350 --> 09:10.010
This lets us choose a origin.

09:10.010 --> 09:12.050
We're going to use Ora's location.

09:12.050 --> 09:21.440
That's that actor location and some radius, some float value that determines how far away this random

09:21.440 --> 09:22.300
point can be.

09:22.310 --> 09:24.050
I'm going to use 300.

09:24.050 --> 09:26.480
In fact, I can promote this to a variable.

09:27.500 --> 09:29.180
And call this radius.

09:29.180 --> 09:34.940
I can even expose it with the eye icon and we can set this to a default value.

09:34.970 --> 09:37.370
I'll set it to a default of 300.

09:37.370 --> 09:44.000
And then because it's exposed, we could even go back to our behavior tree and we can set the radius

09:44.000 --> 09:45.080
here if we like.

09:45.080 --> 09:46.220
So that's handy.

09:46.250 --> 09:51.650
Now, if the actor's valid, we're going to do this and we're going to take that random location that

09:51.650 --> 09:52.730
we get from it.

09:52.730 --> 09:59.000
And what I'd like to do is set the blackboard value of our new location.

09:59.000 --> 10:05.060
So we're going to get that blackboard key selector and we're going to drag off of it and set blackboard

10:05.060 --> 10:07.040
value as vector.

10:08.850 --> 10:11.250
And we're setting it to that random location.

10:12.020 --> 10:13.130
Like so.

10:13.340 --> 10:18.950
And once we're done with that, we're going to finish, execute and return success.

10:18.980 --> 10:22.910
Now get random location in navigable radius could fail.

10:22.910 --> 10:27.080
And really, in that case, maybe we could just pass a failure in here.

10:27.080 --> 10:32.960
So we're going to go ahead and just add a reroute node here and here and just pass that straight in.

10:32.960 --> 10:35.240
And I think that will be fine.

10:35.330 --> 10:42.920
So now we have this go around target task that will get a random point in the navigable radius.

10:42.950 --> 10:49.910
We can go back in here and as soon as we get that random point, now we have this move to location set.

10:49.910 --> 10:53.510
It should be and we can move to that location.

10:53.630 --> 10:56.390
So we're going to drag off of our sequence.

10:56.390 --> 10:58.340
We're going to use another move to.

10:58.340 --> 11:04.060
And for this move to we're going to set the blackboard key to our move to location.

11:04.070 --> 11:07.370
Now we're moving to that random point around the target.

11:07.370 --> 11:13.530
And after attacking, I'd like just a little bit of a delay, maybe a second plus or minus half a second,

11:13.530 --> 11:14.520
something like that.

11:14.520 --> 11:17.730
So after the attack, let's do a wait node.

11:17.730 --> 11:24.660
And for this wait, we're going to have a wait time of one second plus or -0.5.

11:24.990 --> 11:30.390
So there will be an attack and a little delay and then we'll move around the target.

11:30.420 --> 11:37.770
Now, the thing about moving to a random location is we've seen that our enemy could get a bit stuck.

11:37.800 --> 11:42.690
It could have other enemies in the way those don't create holes in the nav mesh after all.

11:42.690 --> 11:47.550
So if we get hung up on this task too long, I want to abort.

11:47.550 --> 11:49.470
And we can do that with a decorator.

11:49.470 --> 11:51.750
I can right click, add decorator.

11:51.750 --> 11:54.780
And there's a special decorator called Time Limit.

11:54.780 --> 11:58.770
If I select that, then the time limit lets me abort.

11:58.770 --> 12:05.520
If the enemy's been struggling a little too long on this move too, so I'll have this set to observer

12:05.520 --> 12:06.810
abort self.

12:06.810 --> 12:08.970
So we'll abort the self.

12:08.970 --> 12:12.360
That's this specific move to node here.

12:12.360 --> 12:19.980
It can abort itself and we won't be stuck in limbo here and the time limit can be something like two

12:19.980 --> 12:20.520
seconds.

12:20.790 --> 12:26.460
So if we're trying to move to a new location around the target, if that takes longer than two seconds,

12:26.490 --> 12:29.880
we'll go ahead and abort and then we can try things again.

12:29.880 --> 12:35.430
So let's see how our go around target works and we can of course change the name of this node.

12:35.430 --> 12:39.540
I'm going to call it find new location around Target.

12:39.960 --> 12:41.940
Let's see how this is going to work.

12:41.940 --> 12:48.150
Let's go back, press play, and we'll see how our melee character behaves.

12:48.150 --> 12:49.230
Attack.

12:49.230 --> 12:50.700
Couple of seconds delay.

12:50.700 --> 12:51.720
Oh, it attacked again.

12:51.720 --> 12:52.560
It moved.

12:52.590 --> 12:53.820
It moved again.

12:53.820 --> 12:58.800
And notice that it moves to a new location, but then it comes in close again.

12:59.580 --> 13:03.590
So this gives it a little bit of a more aggressive behavior.

13:03.600 --> 13:05.550
And of course, we can change parameters.

13:05.550 --> 13:09.750
We can change that radius of the random point and so on.

13:09.750 --> 13:17.430
We can also test this out really close to a pillar here and we'll see that it should not get stuck.

13:17.460 --> 13:23.640
And if it does ever get stuck, there's a two second time limit and it'll go ahead and just abort that

13:23.640 --> 13:27.300
move to for moving to a random location.

13:28.170 --> 13:33.080
So this gives us a little bit more of some frantic behavior for our enemy.

13:33.090 --> 13:34.500
It's going to attack.

13:34.530 --> 13:36.900
It's going to try to find a new location.

13:36.900 --> 13:39.660
Notice it got stuck there because it was trying to move through.

13:39.660 --> 13:43.110
Ora Ora doesn't create a hole in the nav mesh either.

13:43.110 --> 13:51.000
So if it's trying to move and it's stuck after two seconds, we go ahead and try to find another location

13:51.000 --> 13:52.710
after attacking again.

13:52.950 --> 13:56.520
So this gives us a little bit of some safety.

13:57.810 --> 13:59.730
Okay, so that's looking great.

13:59.760 --> 14:02.220
Now, our attack is still pretty boring.

14:02.220 --> 14:08.220
It's still just drawing a debug sphere, but at least we know when it's attacking, when we see those

14:08.220 --> 14:17.040
red spheres and we know that after attacking, there's a second and a new location is found which we

14:17.040 --> 14:23.880
abort if it takes longer than two seconds to do so and we find a new location and attack again.

14:24.120 --> 14:25.050
Excellent.

14:25.080 --> 14:26.940
So this is looking pretty good.

14:26.940 --> 14:32.220
We still do need to actually have our enemies attack and we'll get to that.

14:32.220 --> 14:35.640
But we also want some behavior for our ranged attackers as well.

14:35.670 --> 14:35.970
Right.

14:35.970 --> 14:37.500
They get to attack, too.

14:37.530 --> 14:40.590
So we'll get to those things in the videos to come.

14:40.590 --> 14:43.380
For now, great job and I'll see you soon.
