Patrol not working properly for A* Pathfinding Project Pro Integration

snarlynarwhal

New member
The randomPatrol bool does not seem to get taken into consideration (always random) and the agent occasionally gets stuck at path nodes. I just noticed that putting the agent in the same location as the first waypoint game object makes them stay stuck there on start.
 
Last edited:
Are you able to reproduce it within the demo scene? The demo scene should have the agent continuously moving from one waypoint to the next.
 
It works fine in the demo scene. I have been tweaking variables and cannot get it to work, but it did work for me in the past. I only recently revisited patrolling enemies. I linked to a gif of the broken AI Path and the Inspector for the Patrol Task. I am using the A* Pathfinding Project Pro Integration and RVO Controllers in case either of these matters.

AI keeps trying to go to a (usually the wrong) waypoint.

PS - I just realized this forum does not automatically redirect from http to https and allows insecure logins D:

behavior-tree.PNG

AIPath.PNG
 
Last edited:
What is your arrived distance on the Patrol task? You may need to increase this value.
 
That seemed to help prevent the agent from getting stuck, but he's still going to random nodes. I put a log in Target() and it seems that it gets called anywhere from 1 to 15 times in sequence when the agent reaches a given waypoint. It appears to cycle through them in rapid succession for a split second hence choosing the next waypoint "at random."

I put a log in IAstarAIMovement.HasArrived and sure enough that's also firing multiple times in sequence. That should not be happening right?
 
Last edited:
Calling HasArrived every tick is correct. In version 4.2 of the A* Pathfinding Project Aron added a new property which should help with this situation. Try changing the HasArrived method of the IAStarAIMovment to:

Code:
return agent.reachedDestination;

The agent will now use that new property and it'll hopefully detect when the agent has arrived better.
 
Ahh it worked thank you very much! Just to clarify, did you mean replace the entire function body like so:

And you'll update with next release too, right?

C#:
protected override bool HasArrived()
{
    // The path hasn't been computed yet if the path is pending.
    float remainingDistance;
    if (agent.pathPending || agent.reachedEndOfPath) {
        remainingDistance = float.PositiveInfinity;
    } else {
        remainingDistance = agent.remainingDistance;
    }

    return remainingDistance <= arriveDistance.Value;
}


C#:
protected override bool HasArrived()
{
    return agent.reachedDestination;
}
 
Last edited:
Hello Justin,

I had issues when I added an arrive distance, so I modified the function like so:

Code:
protected override bool HasArrived()
{
    return agent.reachedDestination || agent.remainingDistance < arriveDistance.Value;
}

Any subsequent updates will have the new correct check, right? Don't want to upgrade and have to remember why the AI broke haha.
 
You should only need agent.reachedDestination - it is up to A* to determine if the destination has been reached. Now that version 4.2 of A* is released I'll ensure this is included in the integration.
 
Hi Justin,

I recently upgraded Behavior Designer, Behavior Designer Movement Pack, and the Behavior Designer Movement Pack A* Pathfinding Project Pro integration and the patrols in my game stopped working since IAstarAIMovement got reverted.

The current package has:

C#:
protected override bool HasArrived()
{
    // The path hasn't been computed yet if the path is pending.
    float remainingDistance;
    if (agent.pathPending || agent.reachedEndOfPath) {
        remainingDistance = float.PositiveInfinity;
    } else {
        remainingDistance = agent.remainingDistance;
    }

    return remainingDistance <= arriveDistance.Value;
}

which does not work (patrols just stand still), at least for me.

I had to revert back to the change I made awhile back in order for it to work again:


Code:
protected override bool HasArrived()
{
    return agent.reachedDestination || agent.remainingDistance < arriveDistance.Value;
}

I was hoping the package could get updated with this fix so I do not need to remember to manually update it next time I update Behavior Designer.
 
Top