NavPathSearch
An A* search across a BGE.NavGrid, run a little at a time. Make one with NavGrid.startSearch(), call step(budgetMs) each frame until it returns true, then read status and path.
Moves are 8-way; diagonals can't cut a blocked cell's corner.
Properties
status(string) — ABGE.NavPathStatusvaluepath(Array.<BGE.NavPoint>) — Waypoints once the search has finished: path[0] is the start, the last is the goal (or theexpandedCells(integer) — How many cells the search has expanded so far
Example
CODE
m.search = m.nav.startSearch(fromX, fromY, toX, toY)
' each frame:
if m.search <> invalid and m.search.step(2)
if m.search.status <> BGE.NavPathStatus.failed
m.waypoints = m.search.path
end if
m.search = invalid
end ifConstructor
new NavPathSearch(
grid: BGE.NavGrid,
fromX: float,
fromY: float,
toX: float,
toY: float,
options?: BGE.NavSearchOptions,
): NavPathSearchUse NavGrid.startSearch() instead.
Parameters
grid(BGE.NavGrid)fromX(float)fromY(float)toX(float)toY(float)options(BGE.NavSearchOptions, optional, default: "{}")
Instance Methods
step(budgetMs: integer): boolean
Runs the search for about budgetMs milliseconds.
Parameters
budgetMs(integer)
Returns
boolean— true once the search has finished (any status but searching)
cancel(): void
Stops the search. status becomes failed and path stays empty.
Returns
void