Welcome back.
Now our eye is starting to come along, but now we have to start thinking about how to handle ranged
attackers.
So we have a whole branch on our behavior tree to deal with.
Now, let's say we have an enemy and we have our player controlled character aura.
We know that our enemies will approach Aura until they're a good distance away, at which point they
can start to attack and they're going to be launching projectiles or doing distance based spells and
so on.
But there are some considerations that need to be made.
For one, distance alone is not enough to check what happens if there are obstacles in the way.
If our enemies just stop and start firing obstacles at a wall just because aura is on the other side
of it, they're going to look very dumb.
Now let's take a look at this situation from the top.
Here's a top view.
We have our enemy and aura, and here's some obstacle in the way.
We know that if the enemy fires a projectile, it's simply going to hit the obstacle.
So what kind of behavior would we rather see?
It'd be nicer if our enemy was smart enough to move just a little bit out of the way so that it could
hit aura from just around the corner of the obstacle.
That means it could move down here or it could move up here and hit aura from there.
So how do we program the enemy's AI so that it's smart enough to do this?
One way to solve this problem is with the use of unreal engine's environment query system.
What we can do is we can create something called an environment query.
When we run an environment query, we make use of a generator.
The environment query system has several different types of built in generators that generate a set
of locations or actors around.
Some point we refer to these locations or actors as items.
The system can then ask questions about those items by running a series of user defined tests.
Based on these tests, the items can be scored and our environment query will choose the best item filtering
out all the others.
That did not score as well on the tests that we performed.
For example, we may run a test that checks to see if each item can see the target by performing a line.
Trace those who hit obstacles that might be in the way will not score as favorably as those who hit
the character.
After filtering out all of the items that can't see the character, we have items left that can and
we can only consider these moving forward.
Now we can run additional tests to see which of these remaining items is the best one.
For instance, we can check the distance to the character and choose the closest item.
Once we've determined which of these items is the best item, we can then set a blackboard key to that
item and do whatever we wish in the behavior tree, such as move to that location.
This is just one example of how to use the environment query system and it's how we'll ensure that our
ranged attackers can move to a good location where they can see the player and attack from a distance.
And we'll start setting this up in the videos to come.
I'll see you soon.