Method FindClosestPoint
FindClosestPoint(Vector3, int, int, int)
Find the closest point on the path to a given worldspace target point.
Declaration
public virtual float FindClosestPoint(Vector3 p, int startSegment, int searchRadius, int stepsPerSegment)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | p | Worldspace target that we want to approach |
| int | startSegment | In what segment of the path to start the search. A Segment is a section of path between 2 waypoints. |
| int | searchRadius | How many segments on either side of the startSegment to search. -1 means no limit, i.e. search the entire path |
| int | stepsPerSegment | We search a segment by dividing it into this many straight pieces. The higher the number, the more accurate the result, but performance is proportionally slower for higher numbers |
Returns
| Type | Description |
|---|---|
| float | The position along the path that is closest to the target point. The value is in Path Units, not Distance units. |
Remarks
Performance could be improved by checking the bounding polygon of each segment, and only entering the best segment(s)