WEBVTT

00:06.890 --> 00:08.120
Welcome back.

00:08.420 --> 00:14.600
Now our eye is starting to come along, but now we have to start thinking about how to handle ranged

00:14.600 --> 00:15.440
attackers.

00:15.440 --> 00:19.220
So we have a whole branch on our behavior tree to deal with.

00:19.250 --> 00:24.410
Now, let's say we have an enemy and we have our player controlled character aura.

00:24.860 --> 00:30.290
We know that our enemies will approach Aura until they're a good distance away, at which point they

00:30.290 --> 00:37.430
can start to attack and they're going to be launching projectiles or doing distance based spells and

00:37.430 --> 00:38.120
so on.

00:38.120 --> 00:41.690
But there are some considerations that need to be made.

00:41.720 --> 00:47.780
For one, distance alone is not enough to check what happens if there are obstacles in the way.

00:47.810 --> 00:53.810
If our enemies just stop and start firing obstacles at a wall just because aura is on the other side

00:53.810 --> 00:56.090
of it, they're going to look very dumb.

00:56.120 --> 00:59.510
Now let's take a look at this situation from the top.

00:59.540 --> 01:00.830
Here's a top view.

01:00.860 --> 01:05.600
We have our enemy and aura, and here's some obstacle in the way.

01:05.630 --> 01:11.150
We know that if the enemy fires a projectile, it's simply going to hit the obstacle.

01:11.160 --> 01:13.920
So what kind of behavior would we rather see?

01:13.950 --> 01:20.250
It'd be nicer if our enemy was smart enough to move just a little bit out of the way so that it could

01:20.250 --> 01:23.460
hit aura from just around the corner of the obstacle.

01:23.610 --> 01:28.950
That means it could move down here or it could move up here and hit aura from there.

01:29.130 --> 01:34.200
So how do we program the enemy's AI so that it's smart enough to do this?

01:34.230 --> 01:39.600
One way to solve this problem is with the use of unreal engine's environment query system.

01:39.780 --> 01:43.770
What we can do is we can create something called an environment query.

01:43.800 --> 01:47.880
When we run an environment query, we make use of a generator.

01:47.970 --> 01:54.090
The environment query system has several different types of built in generators that generate a set

01:54.090 --> 01:56.910
of locations or actors around.

01:56.910 --> 02:01.960
Some point we refer to these locations or actors as items.

02:01.980 --> 02:09.390
The system can then ask questions about those items by running a series of user defined tests.

02:09.570 --> 02:16.620
Based on these tests, the items can be scored and our environment query will choose the best item filtering

02:16.620 --> 02:17.700
out all the others.

02:17.700 --> 02:21.540
That did not score as well on the tests that we performed.

02:21.570 --> 02:28.740
For example, we may run a test that checks to see if each item can see the target by performing a line.

02:28.740 --> 02:35.760
Trace those who hit obstacles that might be in the way will not score as favorably as those who hit

02:35.760 --> 02:36.670
the character.

02:36.690 --> 02:42.930
After filtering out all of the items that can't see the character, we have items left that can and

02:42.930 --> 02:45.750
we can only consider these moving forward.

02:45.780 --> 02:51.120
Now we can run additional tests to see which of these remaining items is the best one.

02:51.150 --> 02:56.530
For instance, we can check the distance to the character and choose the closest item.

02:56.550 --> 03:02.580
Once we've determined which of these items is the best item, we can then set a blackboard key to that

03:02.580 --> 03:07.830
item and do whatever we wish in the behavior tree, such as move to that location.

03:08.040 --> 03:13.710
This is just one example of how to use the environment query system and it's how we'll ensure that our

03:13.710 --> 03:19.860
ranged attackers can move to a good location where they can see the player and attack from a distance.

03:19.860 --> 03:22.840
And we'll start setting this up in the videos to come.

03:22.890 --> 03:24.060
I'll see you soon.
