Beispiel #1
0
    public Vector3 GetClosestPoint(Vector3 worldPos, bool includeIntersections = true)
    {
        float   minDst       = float.MaxValue;
        Vector3 closestPoint = Vector3.zero;

        Stretch st = null;

        for (int i = 0; i < stretches.Count; i++)
        {
            st = GetStretch(i);

            Vector3 p   = st.GetClosestPointOnStretch(worldPos);
            float   dst = (worldPos - p).sqrMagnitude;
            if (dst < minDst)
            {
                if (!includeIntersections)
                {
                    if (!st.IsIntersection())
                    {
                        minDst       = dst;
                        closestPoint = p;
                    }
                }
                else
                {
                    minDst       = dst;
                    closestPoint = p;
                }
            }
        }

        return(closestPoint);
    }