Prevent Swivel To Turn During AI Pathfind

Greetings!

I checked these forums and found that people with the same issue as me never got a satisfactory answer.

How can I prevent AIMoveTo (->Random Location) from either:

  1. Choosing a point that is more than 180 degrees from my Deer’s (the AI) forward vector; which would cause it to swivel in place to face the direction of the navpoint.

or preventing this by:

  1. Coding a method for the dear to approach the navpoint indirectly; perhaps by having it approach the navpoint on a curved path, instead of the usual straight line.

There are few ways to achieve this and I think for all of them you will have to create a custom Behavior Tree task. If you want to select a point that is in front of your character or to his side(-90,90), you can create eqs query node and use it to choose random location. For the querier you would create an empty actor in front of the deer that is a bit more than the distance of the mid point of the query area size. Now the new location will always be in front of the deer. Next you have move to location nodes that you can use to go to location. Also Run EQS query has on finished event that you need to use to trigger the move to and also you have output from the EQS query node that will give you array of selected locations(which will be the length of 1 if you have EQS set to single best item). I attached a dumb paint jpg.
For the second thing thing, what I did for my game to have smoother rotating is created a custom move to logic where I generate path points and my character rotates at X speed towards each point and starts moving, but that setup gets more complicated.

1 Like

Hmm… okay. I’m going to have to do some research on EQS Queries and get back to you. Frankly, I currently have no idea what the result of their function would be.

1 Like

For option 2 you could create your own custom PathFollowingComponent that will alter how it handles getting between two different points on a path. I don’t have much more advice on that topic, as I’ve never really implemented anything like that, just read some of the code, and that class seems like it would be an obvious beginning point to do something like that. Build one that can follow curves instead of straight lines.

I’m actually pretty interested in point 1 possibilities. Polysiens idea would work if you are at the start of a move, but I have a similar problem that has slightly different requirements – i want to allow for the AI to take the turns, but I want them to be at a higher cost. I want to dynamically adjust path sections (particularly at the start of a move) that would require say more than a 45-degree turn to hit, to add a significant cost to it.

I have yet to figure out a way to get there.

Hi, for point 1 you could use an EQS cone generator and then optionally score points by dot (to discourage points that are less straight ahead but without completely filtering them out) and distance (if you want it to rather choose points further or closer to the AI). And optionally also a path finding check (if you only want to include points where a path to them exists).

And the eqs query:

2022_08_28_eqs_query


Using an eqs query will generate lots of points where you only need one, which may come at an performance impact (especially if you use a pathfinding test and depending on how often you want to call the eqs query, e.g. calling it on tick with pathfinding may be a bad idea). It could be a bit faster if you manually sample points from a cone one by one and choose the first one that works. For example to manually sample points from a cone (if you would go this way you would rather implement it in C++, since just using an EQS query is simpler and therefore I would rather go with that, this would be just if it costs you too much performance like using it on tick for lots of actors…):