Shaku

Shaku JS

Back To Table of Content

Path Finder

Classes

IGrid

Interface for a supported grid.

Node

A path node.

Constants

PathFinder

Path finder utilitiy. To use it:

  1. Implement a IGrid instance that returns if a grid node is blocking and what's the price to cross it.
  2. Call findPath() with your grid to find a path between start and end points.

Functions

findPath(grid, startPos, targetPos, options)Array.<Vector2>

Find a path between start to target.

getDistance()

Get distance between two points on grid. This method is quick and dirty and takes diagonal into consideration.

IGrid

Interface for a supported grid.

Kind: global class

iGrid.isBlocked(_from, _to) ⇒ Boolean

Check if a given tile is blocked from a given neihbor.

Kind: instance method of IGrid
Returns: Boolean - Can we travel from _from to _to?

Param Type Description
_from Vector2 | Vector3 Source tile index.
_to Vector2 | Vector3 Target tile index. Must be a neighbor of _from.

iGrid.getPrice(_index) ⇒ Number

Get the price to travel on a given tile. Should return 1 for “normal” traveling price, > 1 for expensive tile, and < 1 for a cheap tile to pass on.

Kind: instance method of IGrid
Returns: Number - Price factor to walk on.

Param Type Description
_index Vector2 | Vector3 Tile index.

Node

A path node.

Kind: global class

new Node(position)

Create the node from a position.

Param Type Description
position Vector2 | Vector3 Node position.

node.fCost

Get the node fCost factor.

Kind: instance property of Node

PathFinder

Path finder utilitiy. To use it:

  1. Implement a IGrid instance that returns if a grid node is blocking and what’s the price to cross it.
  2. Call findPath() with your grid to find a path between start and end points.

Kind: global constant

findPath(grid, startPos, targetPos, options) ⇒ Array.<Vector2>

Find a path between start to target.

Kind: global function
Returns: Array.<Vector2> - List of tiles to traverse.

Param Type Description
grid IGrid Grid provider to check if tiles are blocked.
startPos Vector2 | Vector3 Starting tile index.
targetPos Vector2 | Vector3 Target tile index.
options \* Additional options: { maxIterations, ignorePrices, allowDiagonal }

getDistance()

Get distance between two points on grid. This method is quick and dirty and takes diagonal into consideration.

Kind: global function