Is there NavMesh.FindClosestEdge similar function?
Hi
Unfortunately there is no such method at the moment
Just wrote this. Haven’t profiled it but just tested it and it’s doing what I need it to do. Literally just stripped out some code from the RichAI.CalculateWallForce func and added it to my extended RichAI class.
public float3 GetNearestWall(float3 position, out float dist)
{
dist = float.MaxValue;
float3 closest = float.PositiveInfinity;
for (int i = 0; i < wallBuffer.Count; i += 2)
{
float3 point = VectorMath.ClosestPointOnSegment(wallBuffer[i], wallBuffer[i + 1], position);
float distsq = math.lengthsq(point - position);
if (distsq < dist)
{
dist = distsq;
closest = point;
}
}
dist = math.sqrt(dist);
if (!float.IsInfinity(closest.x) && CrowdSimulationBootstrap.Instance.debug)
Debug.DrawLine(position, closest, Color.yellow);
return closest;
}
2 Likes