PathFinding. PathFinder

Grid pathfinder using A* with two optional smoothing passes.

Constructor

new PathFinder(source)

Parameters:
NameTypeDescription
sourceTileCollisionLayer | Vector2

Either a TileCollisionLayer (size and walkability auto-derived) or a Vector2 grid size (user overrides isWalkable).

Example
// Tile-layer driven (most common):
 const pf = new PathFinder(myTileCollisionLayer);
 const path = pf.findPath(player.pos, mousePos);

 // Bare grid with custom walkability:
 const pf = new PathFinder(vec2(50, 50));
 pf.isWalkable = (x, y) => myGrid[y*50 + x] === 0;

Methods

getCost(x, y) → {number}

Default extra cost for stepping on a cell. Returns 0 (free) by default. Override to add cost-weighted terrain (mud, swamp, etc).

Parameters:
NameTypeDescription
xnumber

Tile x

ynumber

Tile y

Returns:
Type: 
number

getNode(x, y) → {PathFinderNode|null}

Get the node at tile coords, or null if out of bounds.

Parameters:
NameTypeDescription
xnumber
ynumber
Returns:
Type: 
PathFinderNode | null

isWalkable(x, y) → {boolean}

Default walkability: if a tile layer was provided, returns true when the cell has no solid collision data; otherwise returns true. Override on the instance or via a subclass.

Parameters:
NameTypeDescription
xnumber

Tile x

ynumber

Tile y

Returns:
Type: 
boolean