Add method to get last path cost to AStar2D
, AStar3D
, and AStarGrid2D
#98409
+44
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a method to return the last total pathfinding cost to
AStar2D
,AStar3D
, andAStarGrid2D
. This method returns theg_score
of the last closest point. This enables it to work both withallow_partial_path
if the end point was unreachable, or with normal pathfinding.g_score
is used instead off_score
as it is more accurate if the path was unreachable but still executed. If the end point was unreachable andallow_partial_path
is false, it will return -1. It also returns -1 if a pathfind action has not been performed yet, such as after first instantiating the class.Closes: godotengine/godot-proposals#5667
Obsoletes: #64150
This PR performed a entire path find operation to return the score, instead of reading it from the last closest point. It was last updated Aug 11, 2022.
Example:
Download: astar_test_pathcost.zip
Video:
astar-path-cost.webm
Blue tiles are 0.5 cost, red tiles are 2 cost, normal tiles are 1 cost. Cost is displayed in a UI element. Towards the end you can see that when clicking on a solid/disabled tile, without partial path the value will return -1 but with it returns the cost of the path closest.