Get as close to target while limiting max path length


I would like the system to give me a path, that would be “at most XXX long” from the start, and is as close to the target point as possible.

In practice, I think that means using “XPath.calculatePartial”, while utilizing some “early exit” condition for when the path is too long already, above some given constant.

How could I make that work? Seems like a reasonably intuitive request imo, the A* should just exit early when it searches in given max length, but I don’t see something that could help me achieve this.

Thank you


Do you want:

  1. A path that is at most X long which brings you as close to the destination as possible.
  2. or, a path that is at most X long which brings the agent as far along the optimal path to the destination as possible.

These paths can be wildly different. Making an agent repeatedly follow type (1) paths will not necessarily bring it to the destination.

Yes I understand the difference and the possible “unoptimality”, but in my case I would really just want (1), = get as close to the destination as possible in a given max range.


Sorry for the late response.
In that case I think you might be able to do this by

  1. setting path.calculatePartial = true;
  2. Using an XPath path instance and create a custom path ending condition that says that any point is a valid target if it either has a G score (cost from the start node) above a certain threshold, or it is the actual target. See PathEndingCondition - A* Pathfinding Project for more details.