AI agent that wait to reach the first destination before going for the second
I am learning how to use the Unity integrated pathfinding functionality.
I have an agent and I would like to see it changing position, based on a set of action that it should perform. For example; it will be idle, then move to position X to perform an action; then move to position Y to perform another action and so on.
So far I did use the example included in the standard assets; where the agent has an AI script that accept a transform from an object in the scene; which is great as starting point.
I did add a second target, and a second set of commands, so after that the destination has been set to target 1, and the move is issued, I set destination to the second target, and then issue another move statement. The problem is that the agent does not reach the first point, and then go to the second; it go straight to the second point. I suppose that the code goes so fast, that as soon as the agent is moving to the first point, the code is already changing the destination to the second point, so the agent goes straight for the second point.
Is there a way to have the agent get to a destination point (and maybe wait there for a specific amount of time), and then move to the second?
Found a property called Pathpending; which seems to hold data if the destination hasn't been reached. I will try to use its output to evaluate if the destination has been reached; and once that will happen, I will change the destination to the next object in the list.
Im not familiar with the code in the example, but Im pretty sure there is a distance check to see if the agent is near his target point before he can be assigned the next. Check if the distance set is maybe too big, or your points are too close together, or you have changed the code and broken something. Really cant tell for sure without being able to see it.
Answer by darshie1976 · Jan 17, 2016 at 03:19 AM
Yes, the distance check is done by pathpending: it return the distance of the agent from the target destination.
I was able to get teh agent to move between points; although it seems to not be able to sync up with the animation when I call the move; but that's a different story.
Your answer
![](https://koobas.hobune.stream/wayback/20220612060131im_/https://answers.unity.com/themes/thub/images/avi.jpg)