Get navigable point in radius with line of sight to target for AI

Hello everyone,

I’m trying to get a position for an AI to move to within a certain radius in which he has line of sight to a certain target (i.e. it is possible to cast a trace from the ai pawn to the target pawn without hitting something). I have thought about using an EQS that generates points in a grid but I don’t think it is possible to pass in some kind of target where the filters should be based on (line of sight from point to target, distance from point to target). I also thought about using the navigation system from c++ but I don’t quite know how to work with that navigation system.

I hope the image below clarifies it a bit, blue is the target here and red has to move to the right(R) position while W would be closer but does not give him line of sight.

88329-sightcheck.png

Any answer in either blueprint or c++ would be greatly appreciated! Bonus points if it could be extendable to other conditions!

Can you give me more details please? The Line of Sight is a cone or is just a straight line? Maybe a draw would be helpful.

I updated my question with an drawing, I hope that clarifies things.

Hi,

I think EQS would fit your needs. Here you have two contexts. The blue and the red one. What you can do is to use pathing grid.
To the pathing grid add a distance test from the blue context to filter points that are closer to the blue context than a given radius. Then you can add another distance test from the red context to score those points that are closer to the red context. Now you have the points in a given radius from red that are closer to blue.
To check if the points are in the the Line of Sight of the blue context you should add a Trace test. This test will do a trace from the blue context to every location returned by the previous tests and return only those that are in line of sight.
With all these three tests you will obtain the positions that are closer to Red, closer to Blue and also are visible from Blue.

Even in the worst case you can create a custom test in c++ (I have done it and it is not complicated, but it is another thread).

Was this what you wanted?

Hope this helps,

Thanks for your answer, that is what I want. However, how could I set the target in that case? Would I have to, in the context, get a value from the AIs blackboard that defines the target? Or is there some way to pass that to the eqs and the context itself?

In my game for example, I have defined two contexts one for the player and the other for the enemies. There you can override four functions: ProvideActorsSet, ProvideSingleActor, ProvideLocationsSet and ProvideSingleLocation depending on what are you looking for.
In my case I have overriden the ProvideActorsSet and ProvideSingleActor to return one specific player/enemy or all of them.
In fact, in any EQS query there is a default context called EnvQueryContext_Querier which is the context of the actor doing the EQS query.

Is it clear? Ask more if you want :wink:

Yeah its clear, thanks! It took me a while to figure out, for some reason all the tests required a locations set instead of an actor set.

This is what I ended up with:

1 Like

Glad it worked!. I do not know why all the tests required a locations set instead of an actor set. Maybe I missed something.