GameSalad
  • Products
    • GameSalad Basic
    • GameSalad PRO
    • GameSalad for Education
  • Community
    • Forums
    • Blog
    • Bug Tracker
  • Games
    • Arcade
    • Featured Games
  • Help
    • Tutorials
    • Cookbook
    • Documentation
    • FAQ
    • Support
  • Marketplace
  • Buy Now
  • Download
  • Account
    • Sign Up
    • Log In
GameSalad Customer Service
  • Knowledge Base
  • News
  • GS Cookbooks
    • Mac Cookbook
    • Windows Cookbook

11 – A* Pathfinding

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.

path find

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

If a cell is 0 or higher, that cell is passable, with the value being the “cost” of entering the cell. You can think of the value as “slowing down” movement through it, which may cause a longer but “faster” path to be chosen.

 

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:

1, 1
1, 2
2, 3
3, 2
3, 1

If there is no valid path from the Start to the Destination (due to cells being blocked), the Path Table will be empty.

Map Layouts

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.

Adjacent Orthogonal Hex
Adjacent maps allow movement from a cell to any of the 8 surrounding cells. Orthogonal maps don’t allow movement on the diagonals. Hex maps treat the table as a hex grid.

Converting from a grid system to a hex system

To get from the table grid layout to a hex layout, follow these steps:

  1. Start with a grid
  2. Spread the columns out so there’s room for a column between them
    Screen Shot 2016-02-23 at 12.56.00 PM
  3. Shift the even rows right
  4. Move row 2 up 1/2 a row, and every other row as far up as it will go.
  5. Change the squares to hexagons.

Demonstration project

  • Pathfind Demo.gameproj (40 KB)

Knowledge Base Search

GS Windows Cookbook

  • GameSalad

  • Download Mac Creator
  • Download Win Creator
  • Download Mobile Viewers
  • Download Other Releases
  • Uninstall GameSalad
  • Games

  • Games of the Month
  • Featured Games
  • Arcade
  • Support

  • Manuals
  • Getting Started
  • Cookbook
  • Video Tutorials
  • Contact Support
  • Community

  • Forums
  • Blog
  • Marketplace
  • Privacy Policy
  • About Us

  • Team
  • Press
  • Press Kit
  • Jobs
  • Terms of Service
A winner is you.
© 2011-2014 GameSalad Inc. All rights reserved.