Please enable JavaScript.
Coggle requires JavaScript to display documents.
A* Pathfinding for River Generation, GetNeighbours(currentTile), Starting…
A* Pathfinding for River Generation
GetNeighbours(currentTile)
+1 to x and y axis
-1 to x and y axis
Vector3Int seTile and swTile
Add to list
List<Vector3Int> neighbours
return neighbours;
Vector3Int neTile and nwTile
return List<Vector3Int>
Starting Variables
Put Start Pos in node list
F = G + H
G = 0
H = calculated distance to end node
GetNeighbours
Put in potentialTiles
Check Validity
If higher, ignore
Else add to Nodes List
Loop through our Nodes
GetNeighbours of current node
Vector3Int startPos
Vector3Int endPos
List<Vector3Int> potentialTiles
List<Vector3Int> validTiles
List<Node> nodes
Node(method for list)
Vector3Int position
int F Cost (G + H)
int G Cost (Distance Between Current Node and start Node)
int H Cost (estimated distance between current node and end node
Loop Starting on Current Position
Add each adjacent tile to a temporary list to check it in a new loop
If an adjacent tile is lower than current position, ignore all tiles above that position. Else if an adjacent tile is above current position ignore those tiles.
Add tiles to a list and give them a F = G + H cost
Loop
Loop
Loop
#
Loop
Our tiles G cost is added to at the begging of the main loop. This indicates how many tiles away from the start position our tiles are. All tiles in this loop will get the current G cost
The H cost is the approximate distance from the end tile which we'll have to find some math to calculate
Add our G cost and our H cost and we'll get our F cost
#
How this could work
Get Z position of current tile
Loop through adjacent tiles
compare our loop tile with current tile z position which we can set as our current z destination
If lower, establish a new z destination
Loop
Loop
#
Then Loop through the list again
If list tiles z position is = to our z destination then we'll add it to our list
1 more item...
Helpers
Variables
Main Logic
Abstract