I have a point graph with obstacles, it can happen that the destination can’t be reached because of it.
How would I get the furthest node that is reachable towards the destination? And say that it reached it’s destination when it reached the furthest node.
I’m doing a scan before checking if the end of the path has been reached, instead of checking if the destination is reached. This works, but somehow doesn’t set the end of path to the correct node when there’s no obstacle in front. It always does one before.
public void SetDestination(Transform _destination)
{
EventSystemNew<bool>.RaiseEvent(Event_Type.KNIGHT_OR_ENEMY_MOVING, true);
destination = _destination;
destinationSetter.target = destination;
if (waitTillDestinationReached != null) StopCoroutine(waitTillDestinationReached);
waitTillDestinationReached = StartCoroutine(WaitTillDestinationReached());
}
private IEnumerator WaitTillDestinationReached()
{
aStarPath.Scan();
yield return new WaitForSeconds(0.5f);
yield return new WaitUntil(() => pathfinder.reachedEndOfPath);
EventSystemNew<bool>.RaiseEvent(Event_Type.KNIGHT_OR_ENEMY_MOVING, false);
}
It’s supposed to go to the yellow square, because the debug log also shows that this destination is right. But it only goes there if I destroy the walls one node further.
pathfinder.reachedEndOfPath only works for the first time i’m setting the target. After the first time, it’s always instantly reached. How can that happen? Or better, how can I solve it?
I got progress, it now works for a few times, and then it becomes instantly for one time. After that it works for a few times, and so on. I’m not sure why this behavior exists, but I’m getting closer
private IEnumerator WaitTillDestinationReached()
{
yield return new WaitForEndOfFrame();
aStarPath.Scan();
destinationSetter.target = destination;
pathfinder.SearchPath();
yield return new WaitUntil(() => !pathfinder.pathPending);
yield return new WaitUntil(() => pathfinder.reachedEndOfPath);
Debug.Log("End Reached");
EventSystemNew<bool>.RaiseEvent(Event_Type.KNIGHT_OR_ENEMY_MOVING, false);
}
That’s odd. Your last code in particular shouldn’t be possible to run instantly. The SearchPath method will set pathPending to true. Can you verify that this is the case?