Hey
I have a custom ITraversalProvider implementation which gives path nodes inside player vision a higher traversal cost, to make the AI take paths which help it stay hidden.
It works by doing a frustum and a linecast check in the traversalprovider to increase the cost of nodes in player vision.
The logic for that works as expected, however the AI will keep moving towards its goal while only considering the path cost.
This in practice makes it so that if there is an alternative path available the AI will choose it even if it is ridiculously long, and if there is no alternative path available it will just walk through player vision without a care in the world.
What I would like to happen here is for the AI to traverse the path that goes through the player vision as far it can without being seen, then wait out of vision until the player turns away and continue the path after its no longer observed by the player.
I can easily control the threshold for choosing a longer path instead of waiting by tuning the penalty value, but I have not figured out how to make the AI come to a stop and wait instead of either walking through the vision or choosing a long alternative path.
I’m using FollowerEntity agent for moving the AI. How could I achieve this result?
Thanks
I assumed I could achieve this by using the movementOverrides in the FollowerEntity, however I didn’t find a way to analyze the upcoming nodes.
I noticed that there is “hierarchicalNodeIndex” in the MovementState class, but I was unable to understand if I could use that to access the upcoming nodes along the path somehow.
In fact I was unable to figure out how to access any nodes along the path at all.
Funny enough I just was helping with another post here that required me to learn more about this feature, but I’m thinking that PathEndingCondition may be what you’re looking for? You could create a PathEndingCondition that takes into account the visibility of the node against the player’s vision frustrum, and assign it to their path, instead of setting node penalties.
Wouldnt that just make the agent always prefer the path where it can reach the edge of vision?
For example, consider following scenario:
This as I understand would make the AI always choose path 1, when the far better option would be path 2 where it could effectively reach the player without making much of a detour.
This is why I like the idea of setting penalties on the nodes, I can have precise control over when a certain agent will consider a path 2 to be too long and choose path 1.
To elaborate, path 1 would be perfect for slow enemies with loud footsteps for example, because the player might walk around to corner where the AI already is waiting silently, and not risking alerting the player by trying to sneak behind them.
Likewise, path 2 would be perfect for fast silent enemy with the main purpose of flanking the player.
What I would suggest is that you sample a point (or multiple) in front of the agent, and then check if that is in the cone of vision. If so, you make the agent stop.
void Update() {
var distance = 2;
var pos = ai.position;
var point = pos + Vector3.ClampMagnitude(ai.steeringTarget - pos, distance);
ai.isStopped = !isInConeOfVision(point);
}
To get more control over the sampled point, you could use ai.GetRemainingPath, and interpolate one or more points along that path.
Simple and customizable solution, can’t believe I didn’t think of this! I guess I was too fixated on solving the problem directly within the pathfinding logic.