Skip to content

Conversation

@nathanrun1
Copy link

I've added support for travel costs. Before, any cell with a weight other than float.MaxValue was essentially treated as fully walkable. However, in some games, it may be beneficial if navigation agents also took into account how much "effort" it takes to travel through a certain cell, in combination with that cell's weight.

E.g. consider an environment where enemies can spend time to destroy obstacles in their path. Ideally, enemies would weigh the option of pathfinding around a destroyable obstacle against the option of destroying it and walking through. However, with the current system, enemies will only ever pathfind around impassable obstacles. Any other cell is treated as if it is completely walkable, as it always inherits its neighbor's weight directly (with the distance added).

To adapt it to this type of scenario, I've added another travel costs buffer to optionally be included in the integration step. If travel costs are used, the travel cost of a cell is added to its own minimum cost, reflecting that the benefit of travelling to this cell is offset by the cost of doing so.

Additionally (although I didn't make this change), this removes the need for the "Walkable" and "Obstacle" sentinel values. You can instead initialize all cell weights to float.MaxValue (indicating no value), and then set the travel cost of any "Obstacle" to float.MaxValue. Walkable cells are simply the default, i.e. a cell with a weight of float.MaxValue and travel cost of 0.

@nathanrun1
Copy link
Author

Actually also just realized that using a shader keyword might be better when toggling usage of travel costs in the integration shader, rather than adding that extra branch.

@nathanrun1 nathanrun1 closed this Oct 7, 2025
@nathanrun1
Copy link
Author

Ok found some issues in my code, my bad. I'll test it fully and fix it before re-opening.

@nathanrun1 nathanrun1 reopened this Oct 8, 2025
@nathanrun1
Copy link
Author

Ok fixed the bug, needed to apply travel costs to the neighbor cost calculation only, and incorporate it into the flow field generation as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant