skip to Main Content

Path-finding – Grid based

Hexagonal grid paths: check demo scenes 204-205 in Path Finding Examples folder

In this case, the hexagonal grid is used as a pattern for the potential paths. Each cell stores costs for crossing hexagonal edges as well as blocking status or ground/water status.

WMSK uses an internal array called cellCosts which is accessible through pathFindingCustomCellCosts property. You can use this property to manually get or set a different cost array if you need to quickly swap between different configurations.

Useful APIs:

FindRoute(startingCell, destinationCell) will return the list of cell indices between the two cells, including them. You can use cell.canCross to determine if the route can pass through any given cell.

PathFindingCellSetSideCost(cell, side, cost): assigns a crossing cost for a cell and a specific side of the hexagon. Note that the cost is applied when moving outside the cell. If you want to set the same cost for a side irrespective of the direction of movement, use the other overloaded method: PathFindingCellSetSideCost (cell1, cell2, cost).

PathFindingCellSetAllSidesCost(cell, cost): assigns the same crossing cost for all sides of the hexagonal cell.

PathFindingCellSetSideCost(cell1, cell2, cost): assigns a crossing cost between cell1 and cell2. The proper side is automatically determined.

PathFindingCellGetSideCost(cell1, side): gets current crossing cost for that cell’s side.

For gameObjects positioned on the viewport, you can also call go.FindRoute(destinationCell, …).

Back To Top