RichAI, AIDestinationSetter, Seeker - How to know that a path is pending?

Hi,

I often find myself in the following situation:

  • An agent reaches its current target
  • Due to that, it gets a new target assigned
  • I want to react at the moment the agent reaches its new target
  • I do NOT want to react RIGHT NOW because the agent has already reached its previous target that is no longer valid

At the moment, I do this in an extremely crude way, by simply assuming we haven’t reached our target for a specific time (say 0.5 seconds) after reaching the last one. But I can’t believe there’s no better way.

However, I can’t find how. Looking at this screenshot:

Please note: this, _aIDestinationSetter and _richAI are the same GameObject (my agent).

So, even though there’s a considerable distance of over 13 meters (in a straight line) between our agent and its (new) target, _richAI claims we’ve reached the destination which is only 0.69m away. It claims that, because it’s unaware of the fact that we have assigned _aIDestinationSetter a new target.

It also claims that it has a valid path and there is no path pending at the moment, which is incorrect information considering that we are having a new target.

How can I reliably check “have I reached the target”? Why is the RichAI unaware of the new target? Is there really no way that I can at least check that the current target is invalidated / that there is no path for the ACTUAL current target?

Hi

The AIDestinationSetter is just a wrapper script for the RichAI.destination property. It will set that property once per frame. If you instead set RichAI.destination directly, then the RichAI.reachedDestination property will update immediately. Since the path will not be calculated at that point, it will use an approximation for a frame or two, but it’s good enough for most use cases. Read more here: IAstarAI - A* Pathfinding Project

Hi and thanks for the quick reply.

I tried this out and it somewhat works. I now set the RichAI.destination whenever I give the AIDestinationSetter a new target (I still think it would be more robust if AIDestinationSetter.target was a property and did this itself).

When I do this, the RichAI’s “reachedDestination” property goes to false (yay), but the “reachedEndOfPath” does not (boo). I usually check “reachedEndOfPath” to see if I have arrived (why didn’t I include “reachedEndOfPath” in the screenshot then? Excellent question!).

So now I changed this so that I’m also checking “reachedDestination” in order to determine whether my agent has arrived at its destination. However, half the time, “reachedDestination” does not seem to properly toggle to true:

image

Yes, that’s a limitation of reachedEndOfPath. The documentation I linked also mentions this.
reachedEndOfPath was added much earlier and a lot of the reason I added reachedDestination was to avoid the design issues of reachedEndOfPath.

Is the destination significantly outside the navmesh? Or is it perhaps above the agent or far below it?

Neither I would say. The agent moves exactly as expected too. Here’s an image outlining everything. Both the player (destination) and the agent are on the navmesh.

One detail: I’m using root motion to move the agent with a script that’s loosely based on the MecanimBridge example.

It looks like the destination is above the agent’s head. That will make the reachedDestination property return false.

Interesting, thank you for clarifying and for the quick replies, much appreciated.