What is pathfinding?
A* pathfinding is a fast way to determine a path through a map in the most efficient way possible, avoiding obstacles along the way. In GameSalad, A* is implemented with the Path Find behavior. This behavior is available in GameSalad 0.14 and later.
The Path Find Behavior
The Map Table is a table consisting of integer columns that define the map you want to find a path through. If a cell in the table is negative, that cell is considered impassible.
Moving from cell 1,1 to 3,3, blocked at 2,2
Moving from cell 1,1 to 3,1. Green path cost is 1+1+1+1=4, red path cost is 5+1=6. Green path is faster.
Using the Path Table
The generated path is stored the the Path Table, which must consist of two integer columns. The 1st column will be the path row, and the 2nd column the path column. Each row in the path table is a cell of the map table, starting from the Start Row and Column, and ending with the Destination Row and Column.
In the movement from cell 1,1 to 3,1 above, the Path Table would be filled in with these values:
If there is no valid path from the Start to the Destination (due to cells being blocked), the Path Table will be empty.
The Map Layout value tells the behavior how the cells of the map are connected to each other, and what kind of movement is allowed. The values are adjacent, orthogonal, and hex.
Converting from a grid system to a hex system
To get from the table grid layout to a hex layout, follow these steps:
- Start with a grid
- Spread the columns out so there’s room for a column between them
- Shift the even rows right
- Move row 2 up 1/2 a row, and every other row as far up as it will go.
- Change the squares to hexagons.