A* agent velocity not set to zero after reaching target

processor

New member
Hi,

I'm using Movement Pack with A* Pathfinding Pro. The graph is generated using Recast Graph. The agent is moving using RichAI component.

I created a simple behavior tree with Follow action. The agent is following the target and when it reaches the target it stops but the problem is that the RichAI.velocity.magnitude is not set to zero. I'm changing the animation of the agent depending on that velocity. When it is zero it plays idle animation from code, larger than zero it plays run animation. The agent now is always having run animation because the velocity is never reaching to zero even when the agent reaches the target and stops moving.

Is there anything I missed? How can I get the current speed of the agent with RichAI? I tested my code with Seek and the same happened. In Seek I can have a workaround because Seek can be terminated once it reaches the target so I can play another action after, but Follow is always running.
 
Last edited:

processor

New member
I have solved this problem by not depending on RichAI.velocity.magnitude for the animation. In code, I'm checking the following to set either the idle or run animation:
C#:
if (!RichAI.canMove || RichAI.velocity.magnitude < 1)
    // set idle animation
else
    // set run animation

I don't know if there is a bug in A* because I'm not getting the correct RichAI.velocity.magnitude when I query it. For now I can't implement idle, walk and run. Only idle and run.

I'm also thinking of a bug in Behavior Tree because I tried the Seek action and when I uncheck "Stop On Task End", the agent disregards "Arrive Distance" value and will seek the target till it collides with it which causes him to move (the target) a little, then RichAI.velocity.magnitude will become zero because the A* has actually reached the target.

But when "Stop On Task End" is ticked, the agent will seek the target and will stop moving before reaching it depending on "Arrive Distance" value. Once the agent reaches the target position minus "Arrive Distance", Behavior Tree will uncheck "RichAI.canMove" which causes the agent to stop, BUT IT'S RichAI.velocity.magnitude REMAINS AS IS NOT ZERO and this causes my issue which is I can't get the correct velocity of the agent.

Any advise regarding this topic is appreciated.
Thanks.
 

processor

New member
I believe it's a bug in A*. I used the following page to fix this issue in A*:

And in Behavior Tree, I set "Arrive Distance" and "Move Distance" equally (ex. 0.75) and less than RichAI.endReachedDistance (ex. 1) then RichAI.velocity.magnitude will reach zero once the agent reaches his target.
 
Top