Options
All
  • Public
  • Public/Protected
  • All
Menu

The NavMesh class is the workhorse that represents a navigation mesh built from a series of polygons. Once built, the mesh can be asked for a path from one point to another point. Some internal terminology usage:

  • neighbor: a polygon that shares part of an edge with another polygon
  • portal: when two neighbor's have edges that overlap, the portal is the overlapping line segment
  • channel: the path of polygons from starting point to end point
  • pull the string: run the funnel algorithm on the channel so that the path hugs the edges of the channel. Equivalent to having a string snaking through a hallway and then pulling it taut.

Hierarchy

  • NavMesh

Index

Constructors

constructor

  • Parameters

    • meshPolygonPoints: PolyPoints[]

      Array where each element is an array of point-like objects that defines a polygon.

    • meshShrinkAmount: number = 0

      The amount (in pixels) that the navmesh has been shrunk around obstacles (a.k.a the amount obstacles have been expanded).

    Returns NavMesh

Properties

Private graph

graph: NavGraph

Private meshShrinkAmount

meshShrinkAmount: number

Private navPolygons

navPolygons: default[]

Methods

Private calculateNeighbors

  • calculateNeighbors(): void

destroy

  • destroy(): void

findClosestMeshPoint

  • findClosestMeshPoint(point: default, maxAllowableDist?: number): { distance: number; point: null | Point; polygon: null | default }
  • Find the closest point in the mesh to the given point. If the point is already in the mesh, this will give you that point. If the point is outside of the mesh, this will attempt to project this point into the mesh (up to the given maxAllowableDist). This returns an object with:

    • distance - from the given point to the mesh
    • polygon - the one the point is closest to, or null
    • point - the point inside the mesh, or null

    Parameters

    • point: default
    • maxAllowableDist: number = ...

    Returns { distance: number; point: null | Point; polygon: null | default }

    • distance: number
    • point: null | Point
    • polygon: null | default

findPath

  • findPath(startPoint: Point, endPoint: Point): null | default[]
  • Find a path from the start point to the end point using this nav mesh.

    Parameters

    • startPoint: Point

      A point-like object in the form {x, y}

    • endPoint: Point

      A point-like object in the form {x, y}

    Returns null | default[]

    An array of points if a path is found, or null if no path

getPolygons

  • getPolygons(): default[]

Private getSegmentOverlap

  • getSegmentOverlap(line1: default, line2: default): null | default[]

isPointInMesh

  • isPointInMesh(point: Point): boolean

Private projectPointToPolygon

  • projectPointToPolygon(point: default, navPoly: default): { distance: number; point: null | default }
  • Project a point onto a polygon in the shortest distance possible.

    Parameters

    • point: default

      The point to project

    • navPoly: default

      The navigation polygon to test against

    Returns { distance: number; point: null | default }

    • distance: number
    • point: null | default

Generated using TypeDoc