path
Problem it solves
You want an enemy or NPC to find a route through a maze or around obstacles to reach a target without getting stuck on walls.
What this block does
Calculates the shortest path between two tile locations on the tilemap while avoiding walls. You can optionally restrict movement so the path only uses a specific tile type (such as roads or grass). Returns a list of tile locations, or undefined if no valid path exists.
The block
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
| start | tiles.Location | null | The starting tile location. |
| end | tiles.Location | null | The destination tile location. |
| onTilesOf | Image | null | (Optional) A specific tile image to restrict movement to, such as a road or dirt tile. |
Returns
tiles.Location[] — An array of tile locations forming the path from start to end, or undefined if no path exists.
Example
let myPath = scene.aStar(tiles.getTileLocation(0, 0), tiles.getTileLocation(9, 7))
Add the extension
Add github:jwunderl/arcade-tilemap-a-star to your project, or open: Import arcade-tilemap-a-star.