WEBVTT

00:06.930 --> 00:08.010
Welcome back.

00:08.010 --> 00:16.410
So we've now created a nice environment query that will return a location that we can reach on our NAV

00:16.410 --> 00:22.530
mesh bounds volume that is the closest to the Querier that can see aura.

00:22.560 --> 00:27.920
This is perfect for our range attackers because they're going to want to be able to see aura.

00:27.930 --> 00:32.610
And so this is how we're going to move our ranged attackers into place.

00:32.700 --> 00:37.140
So let's go back to our behavior tree and see about setting this up.

00:37.170 --> 00:40.320
The first thing we need to do is run that X query.

00:40.350 --> 00:41.610
So how do we do that?

00:41.610 --> 00:47.700
Well, if we drag off of our sequence for the ranged attacker and expand tasks, there's one called

00:47.700 --> 00:49.390
Run X query.

00:49.410 --> 00:57.540
If we select that, then we can choose an X query to run by expanding x request.

00:57.540 --> 01:00.710
And for query template, we can choose our query.

01:00.720 --> 01:03.810
We're going to use find ranged attack position.

01:03.810 --> 01:12.430
I'm going to change the node name here to say get in position to fire or actually let's call it get

01:12.430 --> 01:16.900
fire position because this is not actually moving our AI.

01:16.900 --> 01:20.050
It's just calculating the best position.

01:20.050 --> 01:27.280
Now, after it runs the query, it's going to set one of our blackboard keys that we specify so we can

01:27.280 --> 01:31.210
take our blackboard key and choose which key we want to use.

01:31.210 --> 01:33.400
I'm going to use move to location.

01:33.520 --> 01:41.860
So after running this query, move to location should be set to the location from among those items

01:41.860 --> 01:43.770
that we've filtered out and scored.

01:43.780 --> 01:48.250
So after getting the fire position, we are going to want to move to that location.

01:48.250 --> 01:49.630
So let's drag off.

01:49.630 --> 01:51.520
We'll get a move to task.

01:52.460 --> 01:55.370
And for Move two, we're going to select the blackboard key.

01:55.400 --> 02:02.990
Move to location and I'm going to rename this node to get in fire position.

02:04.660 --> 02:06.730
I'll call it get in firing position.

02:07.180 --> 02:10.750
So we get fire position, we get in fire position.

02:10.750 --> 02:12.190
This looks a little bit confusing.

02:12.190 --> 02:13.660
They're almost the same message.

02:13.660 --> 02:15.400
So I'm going to change this one.

02:15.400 --> 02:16.630
Sorry for changing this so much.

02:16.630 --> 02:20.440
I'm going to call this calculate fire position.

02:20.680 --> 02:23.110
That way it's just a little more clear.

02:23.110 --> 02:28.210
First we calculate it, then we get in fire position and then we can attack.

02:28.210 --> 02:31.360
So at this point, I'm going to use our attack node.

02:31.390 --> 02:39.190
We'll drag off, we'll use tasks attack, and that's going to result in a nice red debug sphere for

02:39.190 --> 02:39.760
now.

02:39.760 --> 02:43.120
And after that I'd like just a little bit of a delay.

02:43.150 --> 02:50.230
So we're going to have a wait here and this one will be one second plus or -0.5.

02:50.680 --> 02:53.440
And there we have our ranged attacker behavior.

02:53.440 --> 02:56.080
Now all that's left is to test it out.

02:56.230 --> 03:04.270
So I'm going to, first of all, save all and go back to our other map, our start up map here.

03:04.270 --> 03:06.850
And we can just play test.

03:06.850 --> 03:11.140
I'm going to hit play and we'll see how far they run before they stop.

03:11.140 --> 03:13.180
It looks like they don't stop.

03:13.180 --> 03:15.160
They just keep running towards us.

03:15.610 --> 03:17.790
So we shouldn't see that.

03:17.800 --> 03:24.010
So what I'm going to do is take my goblin spear and I'm going to get rid of it.

03:24.010 --> 03:29.740
I'm also going to get rid of one of my ranged attackers so we can just test the one and I'm going to

03:29.740 --> 03:31.360
take a look at my behavior tree.

03:31.410 --> 03:33.490
Looks like we're in move to Target.

03:33.490 --> 03:40.240
And then we failed this one and went straight to am I close enough to attack here?

03:40.240 --> 03:43.390
So it's basically doing this melee code.

03:43.420 --> 03:45.520
It does get in fire position.

03:45.520 --> 03:51.460
We can see sometimes it goes to right here, moves to the move to location.

03:52.230 --> 03:57.540
Let's see if we can get our EQs query working more to our liking.

03:57.570 --> 03:59.670
The grid half size was pretty big.

03:59.700 --> 04:05.370
We can lower this to perhaps 500 grid half size.

04:05.400 --> 04:06.420
Let's see if that helps.

04:06.420 --> 04:07.110
Anything.

04:09.090 --> 04:14.010
And it looks like it's coming straight to me, so something isn't right.

04:14.010 --> 04:16.800
And I notice right away that I used a tack.

04:16.830 --> 04:18.930
That's the C plus plus version.

04:18.930 --> 04:21.390
I'd rather use my BT attack.

04:21.390 --> 04:23.070
That's my blueprint version.

04:23.070 --> 04:24.450
That's the one I want to use.

04:24.450 --> 04:26.460
So let's see how that works.

04:26.550 --> 04:27.750
I'm going to press play.

04:29.300 --> 04:31.010
I expect it to pause and attack.

04:31.010 --> 04:32.500
And there it is.

04:32.510 --> 04:39.350
And we can also use obstacles and see if any obstacles block the path.

04:39.350 --> 04:41.900
I'm going to press P to see my nav mesh.

04:41.900 --> 04:48.200
And let's go to Assets Dungeon, and I'm going to get a nice wall here.

04:49.040 --> 04:49.940
Here's a wall.

04:49.940 --> 04:50.980
Four by two.

04:50.990 --> 04:52.320
Nice big wall.

04:52.340 --> 04:55.550
I'm going to rotate it by 90 degrees.

04:56.590 --> 04:58.510
And bring it over here.

04:58.780 --> 05:01.960
That way we can test out obstacles.

05:02.440 --> 05:05.530
So I'm going to press play and get behind this obstacle.

05:08.630 --> 05:11.330
And so far, so good.

05:12.160 --> 05:13.630
I'm going to get behind it here.

05:16.270 --> 05:23.650
And it looks like we got a crash indexing an array out of bounds at or a player controller line 106

05:23.680 --> 05:25.330
here on line 106.

05:25.330 --> 05:33.610
I'm trying to access path path points at a specific point, and I believe it's because I was hitting

05:33.610 --> 05:34.870
that wall.

05:35.260 --> 05:39.580
This should be something we can place a check here for.

05:40.840 --> 05:45.910
And I'm getting red, so I'm just going to control shift B to compile real quick.

05:46.270 --> 05:46.630
Okay.

05:46.630 --> 05:48.610
So we are compiling just fine.

05:49.090 --> 05:56.860
I'm going to check the number of points here before attempting to access this cached destination.

05:56.860 --> 05:59.920
So I'm going to say if.

06:01.380 --> 06:02.640
NAV path.

06:03.570 --> 06:04.810
Path points.

06:04.830 --> 06:05.430
Dot.

06:05.770 --> 06:08.850
Num is greater than zero.

06:11.260 --> 06:15.100
That way we don't go trying to do anything we shouldn't be doing.

06:17.310 --> 06:18.120
There we go.

06:18.720 --> 06:22.290
Okay, so riders throwing a bit of a fit showing everything is red.

06:22.290 --> 06:24.570
So I'm going to go ahead and close out of Ryder.

06:25.420 --> 06:32.020
And I'm going to delete my intermediate and my binaries folders and force writer to make those again.

06:32.740 --> 06:35.140
So I'm going to open with Jetbrains rider.

06:38.120 --> 06:38.720
All right.

06:38.720 --> 06:43.940
So now that things are looking good here, I'm going to go ahead and run.

06:44.690 --> 06:46.880
I was running without debug mode.

06:46.880 --> 06:49.130
I'm going to run in debug mode this time.

06:50.870 --> 06:52.400
Okay, we're back.

06:53.970 --> 06:55.740
I'm going to go ahead and close out of this.

06:55.740 --> 06:57.500
Three by three by three tile.

06:57.510 --> 06:58.260
Don't need it.

06:58.260 --> 07:00.810
I'm going to close my X player context.

07:00.840 --> 07:02.190
Don't need that.

07:02.370 --> 07:07.710
I don't need my BT go around target open and I don't need my attack open.

07:07.710 --> 07:12.900
Although before I close it, I'm going to set the duration for this attack to 0.5.

07:12.900 --> 07:15.690
So we only see that sphere for just a second.

07:15.720 --> 07:20.370
I said duration of the attack, but what I meant was the duration of the debug sphere here.

07:20.370 --> 07:26.670
We're just going to show it for half a second and I'll go ahead and close the attack.

07:26.880 --> 07:32.340
And we've got our behavior tree open and we can play test.

07:32.340 --> 07:39.930
This looks like I have my three goblins back because I crashed and deleting them was a change that was

07:39.930 --> 07:40.950
not kept.

07:41.930 --> 07:45.410
I'm going to just bring in a smaller wall two by two.

07:45.440 --> 07:48.800
This time I'm going to rotate it a little bit.

07:49.410 --> 07:51.480
We'll rotate it about like this.

07:51.750 --> 07:58.080
And I'm also going to select the wall because I don't want this to block the visibility channel as that's

07:58.080 --> 08:00.640
what I'm using for my click to move.

08:00.660 --> 08:08.070
So for collision, I'm going to set collision presets to custom and ignore the visibility and the camera

08:08.070 --> 08:08.970
channels.

08:09.300 --> 08:13.020
I'm going to save all and I'm going to test.

08:13.780 --> 08:14.620
So let's see.

08:14.620 --> 08:15.820
We've got two Rangers.

08:15.820 --> 08:18.340
One melee melee comes up close.

08:18.340 --> 08:20.770
Actually, the Rangers come up close as well.

08:28.030 --> 08:29.740
So we need to see why.

08:29.780 --> 08:34.990
Oh, and that's because we're using the C plus plus attack, which does nothing.

08:34.990 --> 08:36.520
We want to use the blueprint.

08:36.520 --> 08:38.380
Attack, BT attack.

08:38.860 --> 08:40.610
Let's go ahead and save all.

08:40.630 --> 08:42.070
Try this again.

08:42.100 --> 08:43.990
We'll go behind this wall.

08:46.050 --> 08:46.740
Okay.

08:46.740 --> 08:47.970
And it looks like.

08:50.080 --> 08:51.610
We do have an issue.

08:51.610 --> 08:58.540
Our range attackers, their environment query is able to trace and hit me so they don't consider this

08:58.540 --> 09:01.930
wall something that they can't see through.

09:02.500 --> 09:09.550
I would have to go back and set it to block visibility and hide behind it and then they would have to

09:09.550 --> 09:15.490
come around the corner until they can actually see me and then stop at a place where they can shoot

09:15.490 --> 09:16.000
me.

09:26.630 --> 09:28.020
So there they are.

09:28.040 --> 09:29.450
Here they come back.

09:30.900 --> 09:33.750
And they're finding a spot where they can shoot me, it looks like.

09:33.750 --> 09:34.380
Okay.

09:39.340 --> 09:46.510
So I just don't get any response when I click on my wall here with a short press.

09:48.420 --> 09:51.480
If it's a long press, then of course I get my auto run.

09:51.480 --> 09:55.740
But a short press, it's not going to register a hit on this wall.

09:55.920 --> 10:01.380
It's not going to make me walk around the wall because I'm hitting the wall and it's going to try to

10:01.380 --> 10:03.300
walk up onto the wall.

10:03.420 --> 10:10.290
So if we really want the best of both worlds, we may have to have a collision channel specifically

10:10.290 --> 10:14.490
for our click to move or specifically for our AI.

10:14.520 --> 10:16.590
So that's something to think about.

10:16.800 --> 10:24.540
But for now, we do have our range attackers and they're coming up close, but staying a bit of a distance

10:24.540 --> 10:31.170
away so that they can attack from a distance and we can see them attacking there, drawing those debug

10:31.170 --> 10:32.010
spheres.

10:32.040 --> 10:34.080
They're attacking over and over again.

10:34.080 --> 10:39.330
And if I move, they're going to chase, but they're going to chase so that they can see me.

10:39.950 --> 10:45.080
As they're coming around the corners, but they're still staying a bit farther away.

10:45.110 --> 10:46.940
So this is looking pretty good.

10:47.450 --> 10:48.140
Awesome.

10:48.140 --> 10:51.890
So our behavior tree is looking pretty fleshed out.

10:51.890 --> 10:53.220
It's looking pretty good.

10:53.240 --> 10:58.250
We'll playtest, of course, and see if any other edge cases come into play.

10:58.250 --> 11:04.670
But we're now making use of an environment query to find a good ranged position to fire from.

11:04.670 --> 11:08.690
And we've also got our melee attackers here.

11:08.720 --> 11:10.580
They're coming in close.

11:10.610 --> 11:11.660
They're attacking.

11:11.660 --> 11:14.180
They're finding a new location around the target.

11:14.180 --> 11:18.770
So we've got some nice, relatively simple AI working here.

11:18.770 --> 11:20.570
And this is looking pretty good.

11:20.840 --> 11:26.360
So with that, our basic logic for our behavior tree is done.

11:26.360 --> 11:31.050
But all we're doing for our attack is drawing red debug spheres.

11:31.070 --> 11:34.210
We are going to want to actually attack, right?

11:34.220 --> 11:36.200
So that's the next step for us.

11:36.200 --> 11:41.760
We want our enemies to attack and try to do damage and we'll do that in the videos to come.

11:41.760 --> 11:42.850
So great job.

11:42.870 --> 11:44.010
I'll see you soon.
