Greetings.
I try to do a SamplePosition as there is unitys NavMesh component system. I tried to do it this way. My problem is that the original SamplePosition of the NavMesh works a little different, as can be seen in the api. It actually return true/false if there is a sampled position nearby. Therefore i build this function:
private static bool SamplePosition(Vector3 _destination, out NNInfo _hit, float _maximalSamplePositionDistance)
{
_hit = AstarPath.active.GetNearest(_destination, NNConstraint.Walkable);
return (_hit.position - _destination).sqrMagnitude < Mathf.Pow(_maximalSamplePositionDistance, 2);
}
I have not tested other graph types yet but on a recast graph it always finds a node in proximity to the target destination regardless if there actually is a walkable area (a build navmesh as there would be in unity) nearby.
It probably checks the closest voxel, I assume. Because as long as the I check for a point inside the recast graph’s volume, it returns the same position as my “_destination” parameter.
Kind regards.