System.Nullable<Vector3> GetClosestPoint( BBox box )
System.Nullable<Vector3> GetClosestPoint( Vector3 position, float radius )

robot_2Generated
code_blocksInput

Description

The GetClosestPoint method in the NavMesh class is used to find the closest navigable point within a specified bounding box (BBox). This method is useful for determining a valid navigation point that is closest to a given area, which can be particularly helpful in AI pathfinding scenarios where you need to ensure that the AI agent starts or ends its path on a valid part of the navigation mesh.

Usage

To use the GetClosestPoint method, you need to have an instance of the NavMesh class. You can then call this method by passing a BBox object that defines the area within which you want to find the closest navigable point. The method returns a nullable Vector3, which will contain the closest point if one is found, or null if no valid point exists within the specified bounding box.

Example

// Assuming 'navMesh' is an instance of NavMesh and 'box' is a BBox defining the area
Vector3? closestPoint = navMesh.GetClosestPoint(box);

if (closestPoint.HasValue)
{
    // Use closestPoint.Value as the closest navigable point
    Vector3 point = closestPoint.Value;
    // Perform operations with the point
}
else
{
    // Handle the case where no navigable point was found
}