Struct DistanceMetric

Public

Determines how to measure distances to the navmesh.

The default is a euclidean distance, which works well for most things. However, another option is to find nodes which are directly below a point. This is very useful if you have a character, and you want to find the closest node to the character's feet. Then projecting the distance so that we find the closest node as seen from above is a good idea.

See projectionAxis for more info.

The default distance metric is euclidean distance. This is the same as the distance you would measure in 3D space. Shown in the image above are two parts of a navmesh in a side view. One part is colored blue, and one part colored red. Both are walkable. In the background you can see if points are closer to the blue part, or to the red part. You can also see a few query points in black, which show the closest point on the navmesh to that point. The dashed circle around the first query point shows all points which are at the same distance from the query point.

When using ClosestAsSeenFromAbove, the distance along the up direction is ignored. You can see this in the image above. Note how all query points find their closest point directly below them. Notice in particular the difference in behavior for the query point on the slope.

When using ClosestAsSeenFromAboveSoft, the distance along the up direction is instead scaled by distanceScaleAlongProjectionDirection (set to 0.2 by default). This makes it behave almost like ClosestAsSeenFromAbove, but it allows small deviations from just looking directly below the query point. The dashed diamond in the image is similarly the set of points equidistant from the query point. This mode is recommended for character movement since it finds points below the agent, but can better handle situations where the agent, for example, steps off a ledge.

Public Static Methods

ClosestAsSeenFromAbove ()

Returns a DistanceMetric which will find the closest node as seen from above.

Public Static
ClosestAsSeenFromAbove (up)

Returns a DistanceMetric which will find the closest node as seen from above.

Public Static
ClosestAsSeenFromAboveSoft ()

Returns a DistanceMetric which will usually find the closest node as seen from above, but allows some sideways translation if that gives us a node which is significantly closer.

Public Static
ClosestAsSeenFromAboveSoft (up)

Returns a DistanceMetric which will usually find the closest node as seen from above, but allows some sideways translation if that gives us a node which is significantly closer.

Public Static

Public Variables

distanceScaleAlongProjectionDirection

Distance scaling along the projectionAxis.

Public
isProjectedDistance

True when using the ClosestAsSeenFromAbove or ClosestAsSeenFromAboveSoft modes.

Public
projectionAxis

Normal of the plane on which nodes will be projected before finding the closest point on them.

Public

Public Static Variables

Euclidean

Returns a DistanceMetric which will find the closest node in euclidean 3D space.

Public Static Readonly