A* Pathfinding Project

Is there NavMesh.FindClosestEdge similar function?


#1

Is there NavMesh.FindClosestEdge similar function?


#2

Hi

Unfortunately there is no such method at the moment :confused:


#3

@friuns did you figure out a solution or shall I have a gander?


#4

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;
        }