Hi there,
I've noticed the wander task tends to pick a new target destination several times after the initial destination is reached. I'm using this tree to make an entity wander around for some time then stay idle some more using this tree:
Upon debugging the wander task does recalculate a new target many times, I think this is because of the way HasArrived method in the IAstarAIMovement class works:
HasArrived() checks agent.remainingDistance which seems to not be a reliable way to know this since the paths are asynchronous:
These are the documentation commends for remainingDistance and comes with a warning at the end which explains this issue:
I'm not sure what would be the fix for this, maybe wait for the path to be calculated before using agent.remainingDistance for the HasArrived check? I know AiPath calls this when the path is calculated so it could be an aproach?
Any ideas? This is mainly an issue for me because is making my enemy sprites flip left or right several times when getting a new wander destination and looks bad.
I've noticed the wander task tends to pick a new target destination several times after the initial destination is reached. I'm using this tree to make an entity wander around for some time then stay idle some more using this tree:
Upon debugging the wander task does recalculate a new target many times, I think this is because of the way HasArrived method in the IAstarAIMovement class works:
C#:
// There is no success or fail state with wander - the agent will just keep wandering
public override TaskStatus OnUpdate()
{
if (HasArrived()) {
SetDestination(Target());
}
return TaskStatus.Running;
}
HasArrived() checks agent.remainingDistance which seems to not be a reliable way to know this since the paths are asynchronous:
C#:
protected override bool HasArrived()
{
return agent.reachedDestination || agent.remainingDistance < arriveDistance.Value;
}
These are the documentation commends for remainingDistance and comes with a warning at the end which explains this issue:
Remaining distance along the current path to the end of the path.
For the RichAI movement script this may not always be precisely known, especially when
far away from the destination. In those cases an approximate distance will be returned.
If the agent does not currently have a path, then positive infinity will be returned.
Note: This is the distance to the end of the path, which may or may not be at the <see cref="destination"/>. If the character cannot reach the destination it will try to move as close as possible to it.
Warning: Since path requests are asynchronous, there is a small delay between a path request being sent and this value being updated with the new calculated path.
I'm not sure what would be the fix for this, maybe wait for the path to be calculated before using agent.remainingDistance for the HasArrived check? I know AiPath calls this when the path is calculated so it could be an aproach?
Any ideas? This is mainly an issue for me because is making my enemy sprites flip left or right several times when getting a new wander destination and looks bad.