Getting AI Pawn to run away from Player using TargetPoints

Say there were TargetPoints spread around the world(town, village, whatever). The goal is to get the AI pawn to run to one of these Target Points if the Giant(Player) is near it. The question is, how would I get the correct TargetPoint to move to, moving in a way that it doesn’t try to run towards and across the giant if say that point was behind him.

Example. If the giant was dead center at location (0,0,0) and there were two target points at (-100,0 0) and (100, 0, 0). If the ai pawn was say at location (20,0, 0), clearly he should run towards the (100,0, 0) target point instead of the other. How can I calculate the correct target point taking into account the target points location, the pawn’s current location, and the giant/player’s current location? Thanks.

You can ‘get all actors of class’ TargetPoint and loop thru them all subtracting their world locations from the actor world location - doing a test on which is the smallest length of the resulting subtraction. But, for an even cooler method where the AI hides behind the closest point the giant can’t see - you may want to try using the EQS query system. My buddy Hitpawz did a really nice tutorial series how to get this setup - and you can see it in action in the 3rd or 4th video in the series here: https://www.youtube.com/watch?v=8WxiTehK6Kc

I would make a EQS query to find the target point that meets my needs. The result of the query would be the chosen Target Point actor that I store in a blackboard key. Then in the same sequence I perform a moveto task to that target point blackboard key.

The EQS querier is the current pawns the location. You can make a new EQS Context in blueprint that returns the player/or AI’s enemy/giant. The Items in the query would be the target points.

The query itself can use the Actors of class generator of target point. You can use a distance test and a dot test for filtering.

For specific documentation reference EQS system documentation