AI for ranged enemy

Hey everybody.

I’m working on a top-down arcade style shooter and I’m having issues getting the type of enemy behavior I want for my ranged enemies. I’m trying to create a ranged grunt that attempts to keep its distance from the player.

I can get them to attack but I can’t get it to properly evade attempt to evade the player while not just running straight into a wall and sticking there.

I’ve been looking into EQS for this but I’m not having much luck. Normally I’d keep fighting with it but I’ve got a deadline for the end of this week to meet up with a potential financial backer and I don’t want to present completely idiotic ranged AI that either just sit there, wander aimlessly, or chase the player the same way the melee grunts do.

Any tips, tricks, tutorials or anything else would be greatly appreciated.

Hi, I would use EQS for this. So first you should follow the quick start guide for EQS step by step: Environment Query System Quick Start | Unreal Engine Documentation

What I would then do for your setup: When the bot is too close (or too far away) to the player it calls an EQS Query in the behaviour tree to find a new point, with line of sight on the player, and moves to that point

  1. Create a new “Environment Query”

  2. First you would need a generator to generate possible target locations for the bot. Doc: EQS Node Reference: Generators | Unreal Engine Documentation

Depending on how you want to do this you could generate a circle (“Points: Circle”) around the player (with your desired distance as radius) and the let the bot move to the point closest to it (I think that would be the easiest way to keep a fixed distance to the player but you also may try using a grid).

  1. The Circle generator needs to know where the center the circle is. For that it needs a context Doc: EQS Node Reference: Contexts | Unreal Engine Documentation

I would make a new custom context and override the “Provide Single Actor” function and return the player character.

  1. Now the EQS query will generate points around the player, you may want to filter or score them. That is done by tests. Doc: EQS Node Reference: Tests | Unreal Engine Documentation

I would use a trace test to filter by visibility (the context would be the player, so it will do a trace from the point to the player and checks whether it the trace hits something on the way). And for this, in the context you used to get the player you may need to override the “Provide Single Location” function and return the player location there.

And Pathfinding to score the point by the pathlength from the bot (so prefer lesser pathlength and the context would be the querier that’s the bot)

■■■■… Thanks man!

I really need to sit down and take the time to learn more about EQS rather than the bare minimum that I’ve picked at it so far.

I’ll give this a shot and update the “Answered” status.