Options
All
  • Public
  • Public/Protected
  • All
Menu

Module navmesh

navmesh is the core logic package. It is game-engine agnostic, usable outside of Phaser.

Index

References

Classes

Interfaces

Type aliases

Functions

References

default

Renames and exports NavMesh

Type aliases

PolyPoints

PolyPoints: Point[]

Lightweight representation of a Polygon as a series of points.

Functions

buildPolysFromGridMap

  • buildPolysFromGridMap<TileType>(map: TileType[][], tileWidth?: number, tileHeight?: number, isWalkable?: TileWalkableTest<TileType>, shrinkAmount?: number): PolyPoints[]
  • This parses a world that is a uniform grid into convex polygons (specifically rectangles) that can be used for building a navmesh. This is designed mainly for parsing tilemaps into polygons. The functions takes a 2D array that indicates which tiles are walkable and which aren't. The function returns PolyPoint[] that can be used to construct a NavMesh.

    Notes:

    • This algorithm traverses the walkable tiles in a depth-first search, combining neighbors into rectangular polygons. This may not produce the best navmesh, but it doesn't require any manual work!
    • This assumes the world is a uniform grid. It should work for any tile size, provided that all tiles are the same width and height.

    Type parameters

    • TileType

    Parameters

    • map: TileType[][]

      2D array of any type.

    • tileWidth: number = 1

      The width of each tile in the grid.

    • tileHeight: number = 1

      The height of each tile in the grid.

    • isWalkable: TileWalkableTest<TileType> = ...

      Function that is used to test if a specific location in the map is walkable. Defaults to assuming "truthy" means walkable.

    • shrinkAmount: number = 0

      Amount to "shrink" the mesh away from the tiles. This adds more polygons to the generated mesh, but can be helpful for preventing agents from getting caught on edges. This supports values between 0 and tileWidth/tileHeight (whichever dimension is smaller).

    Returns PolyPoints[]

Generated using TypeDoc