Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get last path cost to AStar2D, AStar3D, and AStarGrid2D #98409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theashtronaut
Copy link
Contributor

Adds a method to return the last total pathfinding cost to AStar2D, AStar3D, and AStarGrid2D. This method returns the g_score of the last closest point. This enables it to work both with allow_partial_path if the end point was unreachable, or with normal pathfinding. g_score is used instead of f_score as it is more accurate if the path was unreachable but still executed. If the end point was unreachable and allow_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.

@theashtronaut theashtronaut requested review from a team as code owners October 22, 2024 04:44
* A function to return the last total path cost added to AStar2D, AStar3D and AStarGrid2D.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to get path cost from AStar
2 participants