Sometimes Seek is stuck when the destination changes (AStarProject)

voktu

New member
Hi,

It seems that in some cases, the method `IAstarAIMovement.HasArrived()` return `true` while the agent is still very far from its destination.

After some investigation `agent.remainingDistance <= arriveDistance.Value` seems to be incorrect:
- agent.remainingDistance is the remaining distance to the next waypoint chose by A* and not the final destination.


If fixed locally by replacing `agent.remainingDistance <= arriveDistance.Value` by `(agent.destination - agent.position).sqrMagnitude <= arriveDistance.Value * arriveDistance.Value` in the function `IAstarAIMovement.HasArrived()`.

Best regards
 
I used to have something similar to that but there were some situations where that wouldn't work. I'm trying to think what that situation was though because it does look like that would solve all use cases
 
I second this, it seems that the agent.remainingDistance is always 0 and it is incredibly broken.

Please use voktu's fix this is a godsend.

C#:
protected override bool HasArrived()
        {
            return agent.reachedDestination || (agent.destination - agent.position).sqrMagnitude <= arriveDistance.Value * arriveDistance.Value;
            // below is BROKEN
            //return agent.reachedDestination || agent.remainingDistance <= arriveDistance.Value;
        }
 
Actually I take that back, for seek you will want voktu's fix

For AStar wander you will want to use the original commented out line. This is really poor.
 
Yeah, now you know the struggle that I'm facing. A* works sometimes for one task, but not the same for another. I haven't found a match that works for all use cases.
 
I tried to do a if
agent.remainingDistance < 0 then check the
agent.remainingDistance <= arriveDistance.Value

Ugh... what alternatives do we have to move an enemy towards a player to attack without using navmesh.
 
Any update? I am also trying to use both A* seek and wander, used Voktu's fix for seek, but what about wander? Search is not also working... So, as a result, A* is not useable with BD?
 
Update was, I abandoned behavior design, and used a custom script.

However I also tried to solve the original problem which i did with a custom action here

C#:
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using Pathfinding;

namespace AI {
    [TaskCategory("AI/Movement")]
    [TaskDescription("Has this AI reached its destination?")]
    public class ReachedDestination : Conditional {
        IAstarAI _ai;

        public override void OnAwake() {
            _ai = gameObject.GetComponent<IAstarAI>();
        }

        public override TaskStatus OnUpdate() {
            return (_ai != null && _ai.reachedDestination) ?
                TaskStatus.Success : TaskStatus.Failure;
        }
    }
}

Also this is what i use for movement


C#:
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using Pathfinding;

namespace AI {
    [TaskCategory("AI/Movement")]
    [TaskDescription("Tells AI to move to a position.")]
    public class MoveToPos : Action {
        IAstarAI _ai;
        public SharedVector3 Destination;

        public override void OnAwake() {
            _ai = gameObject.GetComponent<IAstarAI>();
        }

        public override TaskStatus OnUpdate() {
            if (_ai == null || Destination == null) {
                return TaskStatus.Failure;
            }
            else {
                _ai.destination = Destination.Value;
                return TaskStatus.Success;
            }
        }
    }
}
 
Thanks! For the A* wander, with Voctu's fix on seek, with increased arrical distance (25 for my case with 20 wander distance), it is working as it should. But for the search, no way, I could not succeed :/
 
Hi Justin,

I know you're super busy and you just updated the Movement pack but has any of have been resolved? I'm having issues with AStar Seek not completing in all cases (in some cases it does sometimes and other times it hangs - i.e. never returns success) and I'm not exactly sure why.

Also, with the Search node, how difficult would it be to to add a Tag search as well? This would be really useful for setting up gather behaviours for npcs so they could search for the "Visual Effect" layer and say "Firewood" tag.

Thanks,
Nathan
 
Last edited:
Yes - the most recent version of the Movement Pack includes a new A* integration with a destination fix. If you have updated to the latest and it's still not working let me know how to reproduce it within the demo scene.

Also, with the Search node, how difficult would it be to to add a Tag search as well? This would be really useful for setting up gather behaviours for npcs so they could search for the "Visual Effect" layer and say "Firewood" tag.
I can add it to my list, but since tags are slow I do not recommend using them. Instead you should update the target objects shared variable directly.
 
The latest behavior designer movement package has an empty integrations folder besides the read me. I downloaded the a* integration off the site but am still running into the same problem. I described how to recreate it in my post.
 
Hi Justin

So the first issue I had mentioned above about the path's not completing, I believe, had to do with how I was loading cached files for Start. If I scan the terrain on start everything seems to be working as expected. Sorry about that.

Above, you say that instead of seaching for tags i should "update the target objects shared variable directly", I am doing that but the problem I am having is say that I have a bunch of collectable items that all belong to the same layer. If I want an agent to search for a specific type of item how would I do this? The Search node can look for an item of a layer but what if they find something else on that layer than they don't want?

I have this working, the agent wanders until they find an object and then at that point it changes to a Seek node. Seems to work.
Search.PNG


Finally, with he Astar integration, I was having issues with the Wander and Seek nodes stopping when the agent reached their destination. They would just walk in circles. I think this is because the Update Location set to Fixed Update on the Locomotion script. Changing this to Update seems to have resolved the issue. Is this intended? Should NPCs be run off Update? I have the BD UCC Melee scene modified here with Astar integration. You can see Agent Nolan's Wander works properly with Update but not with Fixed Update.


Thank you,
Nathan
 
I just checked and the Search task does require a layermask to search though it would be nice if it had the same options as Can See Object for determining the targets. I will make a note of this, though like you have in your tree using a combination of Can See/Wander/Seek is basically what search is.

They would just walk in circles. I think this is because the Update Location set to Fixed Update on the Locomotion script. Changing this to Update seems to have resolved the issue. Is this intended? Should NPCs be run off Update? I have the BD UCC Melee scene modified here with Astar integration. You can see Agent Nolan's Wander works properly with Update but not with Fixed Update.
That sounds like it's related to the arrived distance or stopping distance. If you increase these values it should work better.
 
Yeah, you were right. I was confused with the AIPath End Reached Distance It seems that a value of 1 take you right to the point, i.e. the npc stops standing on the desitination point. Setting it to 1.5 stops the NPC .5 infront, 2 stops 1 in front. That took a while to figure out.

The other thing I noticed, and correct me if i'm wrong, the Arrive Distance on the Seek node is only used to allow the node to return a success, it has no effect on the AI Path agent, other than the Seek node completes.

Getting my head around A*, apologies a lot of my A* confusion was being directed here.
 
Top