MakeCode Games!

A fan-made community library of MakeCode Arcade games. Visit MakeCode Arcade to make a game!

← Back to extensions

Tilemap A* Pathfinding

Smart pathfinding for tilemaps that lets sprites calculate routes around walls and follow paths automatically.

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

path from $start to $end||on tiles of $onTilesOf block

Parameters

NameTypeDefaultMeaning
starttiles.LocationnullThe starting tile location.
endtiles.LocationnullThe destination tile location.
onTilesOfImagenull(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.