Download

stay a disance from the player

hi, i would like to know if ther is something to get the location of the player(get actorLocation), but getting a radius from it.
It is for an NPC, that i want to go to the player, but dont go directly to it, but stay a circular distance form it delimitated by a radius of x(
modifiable variable).

Hi, easy way would be to set the “Acceptable Radius” for your “Move To” nodes to the radius you want (so the bot will stop at this radius to the player, but will not keep this radius from the player when the player moves to the bot).

A bit more complicated (but the bot would also stay at this distance): you could look into EQS (the quickstart guide and generators, context, tests) and use a “Points: Circle” generator to generate points at a radius around the player (custom context to get the player) and then score them by distance to the querier (the bot), so the bot chooses the point closest to it.

thanks so much, it helped me a lot, but i want the bot to move around the player with that radius instead stay static when it arrives to the radius. Is it posible?

Yes it’s possible, you could use EQS for this.

First you should follow the quickstart guide from epic and rebuild it in your own project step by step to get a feeling for EQS Environment Query System Quick Start | Unreal Engine Documentation

Then

  1. Create a new EQS query.

  2. You need a point for the AI to move to. That’s what a generator does. I would use “Points: Circle” (that will generate points around the specified context). Doc: EQS Node Reference: Generators | Unreal Engine Documentation

  3. You need to specify a context so the generator knows where the center of the circle is (so where to generate the points). Doc: EQS Node Reference: Contexts | Unreal Engine Documentation

In your setup I would create a custom context and override the “Provide Single Actor” Function and return the player character there

  1. As of now this EQS query will generate a set of points in a circle around the player. Now you want to choose one of them (so filter and or score the points). That’s what tests are for Doc: EQS Node Reference: Tests | Unreal Engine Documentation

If you just want the AI to move in a circle around the player I would use Dot score the points and Pathfinding to score and filter. So the dot so the AI will move the circle in the direction it started and the Pathfinding to move to the point in the circle that is closest to the AI but filter too close points out (else your AI might just stay at one point without moving)

And both tests would need a context too, which would be the AI Bot (the eqs querier) cause you want to get the pathlength from the bot to the point and also do the dot product with the bots rotation.

And then you would call this eqs query from the behaviour tree of the bot and then let the bot move to the output.

yes, It worked.thanks so much,i have just a small problem: when the player stay quiet in a place the bot do some circular movement but it stop at one moment. i want it to move all time instead the player is quiet. On the other hand, im trying to make a random value in range to stop doing that and chase the player, but every bot that spawn get a diferent value of this in the blacboard so i want the same for everyone. And finally when the number of bots arrive to this random value, they chase the player, the problem is that for that i u “get all acators of class”, so they do it at the moment the last one is spawned, but i want to do it when the last one has arrived to the zone they are walking in circles. Thanks so much.

Glad I can help :slight_smile:

  • Can you show the behaviour tree of the bot?

For the second part I’m not sure I understand what you want to do. So you spawn bots -> they move to the player -> then they move in circles around the player?
After some time you want them (all bots on the map?, or just the bots around the player?) to start chasing the player. Or does the random number mean, when this number of bots arrive around the player the bots start chasing the player? (all bots on the map? or just all the bots around the player?) [HR][/HR]

What do they do, chase the player? (although I thought that was when the “number of bots arrive to this random value” and not when the last of them gets spawned)

And with zone you mean the player/area around the player?

yes, sorry i’ll try to explain better. i spawn bots->they move to the player but stay in the radius u told me before(acceptable radius: X)-> so they start moving in circles around the player-> then when the number of bots that are in this radius is equal to the random int i had set(for example 4) all this bots that are doing that go to chase the player.
the problem right now is that they chase the player at the moment the number of actors is equal to the random int, but i want to do it when the last one arrives to the zone, not in the momen it spawns.

Ah, ok. So in the code where you check whether the number of bots is equal to the random int try doing this: when you get all actors of class do a for each loop and check the distance from each bot to the player and only count those bots that are close enough to the player.

So basically something like this (depending on how/where you check whether the number of bots is equal to the random int your code would look different)

i get it. thanks so much. the ony thing that isn’t working good at all is the EQS of the walking in circles arrounf the player. i’ll show you how i have it and maybe u can tell me what’s wrong.

I haven’t actually implemented a bot who runs in circles (maybe I will in the next days) , so I can only guess whats wrong.

First your Pathlength is set to “prefer greater” meaning the bot will try to go to the point in the circle farthest away from it (so just run through the player to the other side) -> I would set it to “prefer lesser”, so inverse the scoring.
Second the dot is there so the bot not only goes to the next point in the circle closest to it (Pathlenght) but also scores whether the next point is in front of it or not (dot product will return 1 when the point directly in front of the bot, -1 when the point is directly behind the bot and 0 if the point is directly left/right from the bot and else something in between).
And I would try using 2D instead of 3D in the dot.

If those steps above do not work, how are your bots behaving?