LittleJS PathFinder Plugin
- Grid-based A* pathfinder with two-pass smoothing for natural-looking paths
- Works directly on a TileCollisionLayer, or override isWalkable/getCost for any grid
- Debug visualization via engine debug primitives (stripped in release builds)
- Port of frankforce.com pathFindingBase.cpp (2018)
- Source
Classes
Methods
(static) PathFinder#findPath(startPos, endPos) → {Array.<Vector2>}
Find a path from startPos to endPos in world space. Returns an array of world-space Vector2 points; empty array if no path exists.
Start and end are snapped to the nearest walkable tile via getNearestClearNode. Intermediate points are tile centers unless the string-pulling smoothing pass moves them off-grid.
| Name | Type | Description |
|---|---|---|
startPos | Vector2 | World-space start |
endPos | Vector2 | World-space end |
- Source
- Type:
- Array.<Vector2>
(static) PathFinder#getNearestClearNode(worldPos, searchRangeopt, rebuildopt) → {PathFinderNode|null}
Find the clear (walkable, zero-cost) node closest to the given world position. Spirals outward in expanding boxes until a clear node is found or the search range is exhausted. Useful for snapping a click or NPC spawn position to the nearest open tile.
By default, calls buildNodeData() first so it works correctly on a fresh PathFinder. If you're calling it many times in a row with unchanged walkability, pass rebuild=false and call buildNodeData() once externally to avoid redundant work.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
worldPos | Vector2 | |||
searchRange | number | <optional> | 10 | Max box-radius in tiles |
rebuild | boolean | <optional> | true | Whether to call buildNodeData first |
- Source
- Type:
- PathFinderNode |
null
(static) PathFinder#tileToWorld(x, y) → {Vector2}
Convert integer tile coords to the world-space center of that tile.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
- Type:
- Vector2
(static) PathFinder#worldToTile(worldPos) → {Vector2}
Convert a world-space position to integer tile coords (no clamping).
| Name | Type | Description |
|---|---|---|
worldPos | Vector2 |
- Source
- Type:
- Vector2