How can i get shortest distance of point A to navmesh

question0205
I want to know shortest distance of point A to navmesh.
(Length of purple line in image)
point A is outside of navmesh.
What should i do?

1 Answer

1
float distance = -1;
if( NavMesh.SamplePosition(point,out var sample,float.MaxValue,~0) )
{
    distance = Vector3.Distance( point , sample.position );
}

Thank you. It's exactly what I wanted.