Hi, i'm using lastest A* pro 4.3.79. There are 2 main problems in wander (2D flag on):
In line 37 u should check also ReachedEndOfPath , something like if (!HasPath() || HasArrived() || ReachedEndOfPath()) {
Maybe is a new flag of A* beta, but with that check agents will not be stuck forever trying to get on a wall (image ex.jpg).
There is a possibility that the agent have a path but cannot reach it. To fix that case my final code of line 37 is:
if ((!HasPath() || HasArrived() || ReachedEndOfPath()) || (!HasPending() && !ReachedEndOfPath() && !HasArrived()) ){
But the root problem is the use of:
protected Vector3 SamplePosition(Vector3 position)
{
return (Vector3)AstarPath.active.GetNearest(position).node.position;
}
Return the Nearest node, but this could be a wall, like in the image. U should check first if is walkable (node.Walkable).
And I suppose that
SetDestination(SamplePosition(destination));
return true;
should be
return SetDestination(SamplePosition(destination));
Second problem is that if wander is the first action, the agent select something outside the graph (ex1.jpg). In the image i've 3 agents and at the start they run always in that points. A stupid fix is to wait half second before the wander. Maybe this is a problem with my scripts order, not a big trouble.
In line 37 u should check also ReachedEndOfPath , something like if (!HasPath() || HasArrived() || ReachedEndOfPath()) {
Maybe is a new flag of A* beta, but with that check agents will not be stuck forever trying to get on a wall (image ex.jpg).
There is a possibility that the agent have a path but cannot reach it. To fix that case my final code of line 37 is:
if ((!HasPath() || HasArrived() || ReachedEndOfPath()) || (!HasPending() && !ReachedEndOfPath() && !HasArrived()) ){
But the root problem is the use of:
protected Vector3 SamplePosition(Vector3 position)
{
return (Vector3)AstarPath.active.GetNearest(position).node.position;
}
Return the Nearest node, but this could be a wall, like in the image. U should check first if is walkable (node.Walkable).
And I suppose that
SetDestination(SamplePosition(destination));
return true;
should be
return SetDestination(SamplePosition(destination));
Second problem is that if wander is the first action, the agent select something outside the graph (ex1.jpg). In the image i've 3 agents and at the start they run always in that points. A stupid fix is to wait half second before the wander. Maybe this is a problem with my scripts order, not a big trouble.
Attachments
Last edited: