How To: Test if the target is not reachable

Hello,

I am using AIPath and the Seeker Component to navigate my AI. I have certain areas that should not be reachable by the AI, because I have set the nodes between the Target and the AI to “walkable = false”.

If I set the target of my AIPath to the destination that should not be reachable, it moves to the edge and then it says “TargetReached” but in reality, that “target” has not been reached, just the nearest point to the target that is walkable was reached. My problem is not that he just walks over the “unwalkable” nodes, my problem is that I need to know for my further algorithm, if the actual target was reached or if the path is just a smaller substitution of the actual path with the actual target position.

Do you have any ideas, how I can test if the target that was reached is the initial target?

In the AIPath, it is this line:

if (currentWaypointIndex == vPath.Count-1 && targetDist <= endReachedDistance) { if (!targetReached) { targetReached = true; OnTargetReached (); }

I think, that the AIPath takes the right target Transform, uses it to call seeker.StartPath (GetFeetPosition(), targetPosition); … and then just uses the calculated path, which last node is the node before the edge.

I can’t find anything on the Path Documentation that would tell me if the path could completely calculated.

Please help, I am confused.

Hi

The easiest thing to do is just to check for the distance between the end of the path and the actual target you want to reach. If that is greater than some threshold you define, you say the target was not reached.
(this is assuming you actually want to make the character walk to that closest point anyway, if you need to know this before the character even starts walking, there are some other tricks you can do).

Thank you for the fast answer! Seems logical and pretty easy.

I think I was just too lost in the documentation, searching for this function.

I am sorry, but after testing I have another issue I can’t quite solve. It is related to my initial problem.

I do check the distance between the end of the path and my target position. My Debug Log tells me the Distance is 0, but even if I look in the Editor it shows that the path goes only to the edge and not until the actual end.

Can it be that the paths endnote is the initial target but the actual path is shorter?

My new code:
public bool NewTarget(Transform _target) { Pathfinding.ABPath path = seeker.StartPath(this.GetFeetPosition(), _target.position) as Pathfinding.ABPath; Debug.Log(path.endPoint + " - " + _target.position); if (Vector3.Distance(path.endPoint, _target.position) > (this.endReachedDistance + this.marginTest)) { return false; } else { this.target = _target; return true; } }

Hi

You have just submitted the path for calculation, but it hasn’t been calculated yet, so it doesn’t know where the end point will be.

You need to wait until the path has been calculated.
If you really need to know it directly, call:
AstarPath.WaitForPath (path);
before checking the distance.

However if you have many agents or long paths, this can have performance implications.