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;

Members

debug

Properties
TypeDescription
boolean

If true, draw debug visualization during findPath

debugTime

Properties
TypeDescription
number

Debug primitive lifetime in seconds (0 disables drawing)

heuristicWeight

Properties
TypeDescription
number

A* heuristic multiplier (1 = admissible, higher = greedier)

maxLoop

Properties
TypeDescription
number

Maximum A* expansions before giving up

nodes

Properties
TypeDescription
Array.<PathFinderNode>

Flat row-major array of size.x*size.y nodes

size

Properties
TypeDescription
Vector2

Grid dimensions in tiles

smoothPath

Properties
TypeDescription
boolean

If true, post-process paths with two-pass smoothing

tileLayer

Properties
TypeDescription
TileCollisionLayer | undefined

Tile layer driving walkability, if any

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