Constructors

  • Constructs a new navigation mesh query object.

    Parameters

    Returns NavMeshQuery

    Example

    const query = new NavMeshQuery(navMesh);
    

    Example

    const query = new NavMeshQuery(navMesh, { maxNodes: 2048 });
    
  • Constructs a navigation mesh query object from a raw object.

    Parameters

    Returns NavMeshQuery

Properties

defaultFilter: QueryFilter

Default query filter.

defaultQueryHalfExtents: {
    x: number;
    y: number;
    z: number;
}

Default search distance along each axis.

Type declaration

  • x: number
  • y: number
  • z: number

Methods

  • Returns the closest point on the given polygon to the given position.

    Parameters

    • polyRef: number

      The reference of the polygon

    • position: Vector3

      The position to find the closest point to

    Returns {
        closestPoint: {
            x: number;
            y: number;
            z: number;
        };
        isPointOverPoly: boolean;
        status: number;
        success: boolean;
    }

    • closestPoint: {
          x: number;
          y: number;
          z: number;
      }
      • x: number
      • y: number
      • z: number
    • isPointOverPoly: boolean
    • status: number
    • success: boolean
  • Finds a straight path from the start position to the end position.

    Parameters

    • start: Vector3

      the start position

    • end: Vector3

      the end position

    • Optional options: {
          filter?: QueryFilter;
          halfExtents?: Vector3;
          maxPathPolys?: number;
          maxStraightPathPoints?: number;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional halfExtents?: Vector3

        The search distance along each axis. [(x, y, z)]

        Default

        this.defaultQueryHalfExtents
        
      • Optional maxPathPolys?: number

        The maximum number of polygons the path array can hold. [Limit: >= 1]

        Default

        256
        
      • Optional maxStraightPathPoints?: number

        The maximum number of points the straight path arrays can hold. [Limit: > 0]

        Default

        256
        

    Returns {
        error?: {
            name: string;
            status?: number;
        };
        path: Vector3[];
        success: boolean;
    }

    an array of Vector3 positions that make up the path, or an empty array if no path was found.

    • Optional error?: {
          name: string;
          status?: number;
      }

      Error information if the path computation failed.

      • name: string

        Description of the error.

      • Optional status?: number

        A dtStatus status code if relevant.

    • path: Vector3[]

      The result path.

    • success: boolean

      Whether a path was successfully computed.

  • Destroys the NavMeshQuery instance

    Returns void

  • Finds the closest point on the NavMesh to the given position.

    Parameters

    • position: Vector3

      the position to find the closest point to

    • Optional options: {
          filter?: QueryFilter;
          halfExtents?: Vector3;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional halfExtents?: Vector3

        The search distance along each axis. [(x, y, z)]

        Default

        this.defaultQueryHalfExtents
        

    Returns {
        isPointOverPoly: boolean;
        point: {
            x: number;
            y: number;
            z: number;
        };
        polyRef: number;
        status: number;
        success: boolean;
    }

    the result of the find closest point operation

    • isPointOverPoly: boolean
    • point: {
          x: number;
          y: number;
          z: number;
      }
      • x: number
      • y: number
      • z: number
    • polyRef: number
    • status: number
    • success: boolean
  • Finds the polygon nearest to the given position.

    Parameters

    • position: Vector3
    • Optional options: {
          filter?: QueryFilter;
          halfExtents?: Vector3;
      }
      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional halfExtents?: Vector3

        The search distance along each axis. [(x, y, z)]

        Default

        this.defaultQueryHalfExtents
        

    Returns {
        isOverPoly: boolean;
        nearestPoint: {
            x: number;
            y: number;
            z: number;
        };
        nearestRef: number;
        status: number;
        success: boolean;
    }

    • isOverPoly: boolean
    • nearestPoint: {
          x: number;
          y: number;
          z: number;
      }
      • x: number
      • y: number
      • z: number
    • nearestRef: number
    • status: number
    • success: boolean
  • Finds a path from the start polygon to the end polygon.

    Parameters

    • startRef: number

      the reference id of the start polygon.

    • endRef: number

      the reference id of the end polygon.

    • startPosition: Vector3

      position within the start polygon.

    • endPosition: Vector3

      position within the end polygon.

    • Optional options: {
          filter?: QueryFilter;
          maxPathPolys?: number;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional maxPathPolys?: number

        The maximum number of polygons the path array can hold. [Limit: >= 1]

        Default

        256
        

    Returns {
        polys: UnsignedIntArray;
        status: number;
        success: boolean;
    }

    The polys array returned must be freed after use.

    findPathResult.polys.destroy();
    
  • Finds the polygons along the navigation graph that touch the specified circle.

    Parameters

    • startRef: number

      Reference of polygon to start search from

    • centerPos: Vector3

      Center of circle

    • radius: number

      Radius of circle

    • Optional options: {
          filter?: QueryFilter;
          maxPolys?: number;
      }
      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional maxPolys?: number

        The maximum number of polygons the result arrays can hold.

        Default

        256
        

    Returns {
        resultCost: number[];
        resultCount: number;
        resultParents: number[];
        resultRefs: number[];
        status: number;
        success: boolean;
    }

    • resultCost: number[]
    • resultCount: number
    • resultParents: number[]
    • resultRefs: number[]
    • status: number
    • success: boolean
  • Returns a random point on the navmesh.

    Parameters

    • Optional options: {
          filter?: QueryFilter;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        

    Returns {
        randomPoint: {
            x: number;
            y: number;
            z: number;
        };
        randomPolyRef: number;
        status: number;
        success: boolean;
    }

    a random point on the navmesh

    • randomPoint: {
          x: number;
          y: number;
          z: number;
      }
      • x: number
      • y: number
      • z: number
    • randomPolyRef: number
    • status: number
    • success: boolean
  • Returns a random point on the NavMesh within the given radius of the given position.

    Parameters

    • position: Vector3

      the center of the search circle

    • radius: number

      the radius of the search circle

    • Optional options: {
          filter?: QueryFilter;
          halfExtents?: Vector3;
          startRef?: number;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional halfExtents?: Vector3

        The search distance along each axis. [(x, y, z)]

        Default

        this.defaultQueryHalfExtents
        
      • Optional startRef?: number

        The reference id of the polygon to start the search from. If not provided, the nearest polygon to the position will be used.

    Returns {
        randomPoint: Vector3;
        randomPolyRef: number;
        status: number;
        success: boolean;
    }

    • randomPoint: Vector3
    • randomPolyRef: number
    • status: number
    • success: boolean
  • Finds the straight path from the start to the end position within the polygon corridor.

    This method peforms what is often called 'string pulling'.

    The start position is clamped to the first polygon in the path, and the end position is clamped to the last. So the start and end positions should normally be within or very near the first and last polygons respectively.

    The returned polygon references represent the reference id of the polygon that is entered at the associated path position. The reference id associated with the end point will always be zero. This allows, for example, matching off-mesh link points to their representative polygons.

    If the provided result arrays are too small for the entire result set, they will be filled as far as possible from the start toward the end position.

    Parameters

    • start: Vector3

      path start position

    • end: Vector3

      path end position

    • path: number[] | UnsignedIntArray

      an array of polygon references that represent the path corridor

    • Optional options: {
          maxStraightPathPoints?: number;
          straightPathOptions?: number;
      }

      additional options

      • Optional maxStraightPathPoints?: number

        The maximum number of points the straight path arrays can hold. [Limit: > 0]

        Default

        256
        
      • Optional straightPathOptions?: number

        Options for dtNavMeshQuery::findStraightPath

        Add a vertex at every polygon edge crossing where area changes. DT_STRAIGHTPATH_AREA_CROSSINGS = 1

        Add a vertex at every polygon edge crossing. DT_STRAIGHTPATH_ALL_CROSSINGS = 2

        Default

        0
        

    Returns {
        status: number;
        straightPath: FloatArray;
        straightPathCount: number;
        straightPathFlags: UnsignedCharArray;
        straightPathRefs: UnsignedIntArray;
        success: boolean;
    }

    the straight path result

    The straightPath, straightPathFlags, and straightPathRefs arrays returned must be freed after use.

    findStraightPathResult.straightPath.destroy();
    findStraightPathResult.straightPathFlags.destroy();
    findStraightPathResult.straightPathRefs.destroy();
    • status: number
    • straightPath: FloatArray

      The straight path points.

    • straightPathCount: number

      The number of points in the straight path.

    • straightPathFlags: UnsignedCharArray

      The straight path flags.

    • straightPathRefs: UnsignedIntArray

      The reference ids of the visited polygons.

      Detour.DT_STRAIGHTPATH_START Detour.DT_STRAIGHTPATH_END Detour.DT_STRAIGHTPATH_OFFMESH_CONNECTION

    • success: boolean
  • Gets the height of the polygon at the provided position using the height detail.

    Parameters

    • polyRef: number

      the reference id of the polygon.

    • position: Vector3

      a position within the xz-bounds of the polygon.

    Returns {
        height: number;
        status: number;
        success: boolean;
    }

    • height: number
    • status: number
    • success: boolean
  • Moves from the start to the end position constrained to the navigation mesh.

    Parameters

    • startRef: number

      the reference id of the start polygon.

    • startPosition: Vector3

      a position of the mover within the start polygon.

    • endPosition: Vector3

      the desired end position of the mover.

    • Optional options: {
          filter?: QueryFilter;
          maxVisitedSize?: number;
      }
      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional maxVisitedSize?: number

        The maximum number of polygons the output visited array can hold.

        Default

        256
        

    Returns {
        resultPosition: {
            x: number;
            y: number;
            z: number;
        };
        status: number;
        success: boolean;
        visited: number[];
    }

    The result of the move along surface operation.

    • resultPosition: {
          x: number;
          y: number;
          z: number;
      }
      • x: number
      • y: number
      • z: number
    • status: number
    • success: boolean
    • visited: number[]
  • Finds polygons that overlap the search box.

    Parameters

    • center: Vector3

      The center of the search box

    • halfExtents: Vector3

      The search distance along each axis

    • Optional options: {
          filter?: QueryFilter;
          maxPolys?: number;
      }
      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional maxPolys?: number

        The maximum number of polygons the search result can hold.

        Default

        256
        

    Returns {
        polyCount: number;
        polyRefs: number[];
        status: number;
        success: boolean;
    }

    • polyCount: number
    • polyRefs: number[]
    • status: number
    • success: boolean
  • Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.

    This method is meant to be used for quick, short distance checks.

    If the path array is too small to hold the result, it will be filled as far as possible from the start postion toward the end position.

    The raycast ignores the y-value of the end position. (2D check.) This places significant limits on how it can be used.

    Using the Hit Parameter (t)

    If the hit parameter is a very high value, then the ray has hit the end position. In this case the path represents a valid corridor to the end position and the value of hitNormal is undefined.

    If the hit parameter is zero, then the start position is on the wall that was hit and the value of hitNormal is undefined.

    If 0 < t < 1.0 then the following applies:

    distanceToHitBorder = distanceToEndPosition * t
    hitPoint = startPos + (endPos - startPos) * t

    Use Case Restriction

    Consider a scene where there is a main floor with a second floor balcony that hangs over the main floor. So the first floor mesh extends below the balcony mesh. The start position is somewhere on the first floor. The end position is on the balcony.

    The raycast will search toward the end position along the first floor mesh. If it reaches the end position's xz-coordinates it will indicate FLT_MAX,(no wall hit), meaning it reached the end position. This is one example of why this method is meant for short distance checks.

    Parameters

    • startRef: number

      the reference id of the start polygon.

    • startPosition: Vector3

      a position within the start polygon representing the start of the ray

    • endPosition: Vector3

      the position to cast the ray toward.

    • Optional options: {
          filter?: QueryFilter;
          prevRef?: number;
          raycastOptions?: number;
      }

      additional options

      • Optional filter?: QueryFilter

        The polygon filter to apply to the query.

        Default

        this.defaultFilter
        
      • Optional prevRef?: number

        Optional parent of start ref. Used during for cost calculation.

      • Optional raycastOptions?: number

        Determines how the raycast behaves.

        // Raycast should calculate movement cost along the ray and fill RaycastHit::cost DT_RAYCAST_USE_COSTS = 1

        Default

        0
        

    Returns {
        hitEdgeIndex: number;
        hitNormal: Vector3;
        maxPath: number;
        path: number[];
        pathCost: number;
        status: number;
        success: boolean;
        t: number;
    }

    • hitEdgeIndex: number

      The index of the edge on the final polygon where the wall was hit.

    • hitNormal: Vector3

      The normal of the nearest wall hit.

    • maxPath: number

      The maximum number of polygons the path can contain.

    • path: number[]

      The reference ids of the visited polygons.

    • pathCost: number

      The cost of the path until hit.

    • status: number

      The status of the raycast.

    • success: boolean

      Whether the raycast was successful.

    • t: number

      The hit parameter.