Beispiel #1
0
    public static Vector3 GetMiddleOfXVector(Vector3[] arrayVect)
    {
        Vector3 sum = Vector3.zero;

        for (int i = 0; i < arrayVect.Length; i++)
        {
            if (ExtVector3.IsNullVector(arrayVect[i]))
            {
                continue;
            }

            sum += arrayVect[i];
        }
        return((sum).normalized);
    }
Beispiel #2
0
    /// <summary>
    /// get closest point from an array of points
    /// </summary>
    public static Vector3 GetClosestPoint(Vector3 posEntity, Vector3[] arrayPos, ref int indexFound)
    {
        float sqrDist = 0;

        indexFound = -1;

        int firstIndex = 0;

        for (int i = 0; i < arrayPos.Length; i++)
        {
            if (ExtVector3.IsNullVector(arrayPos[i]))
            {
                continue;
            }

            float dist = (posEntity - arrayPos[i]).sqrMagnitude;
            if (firstIndex == 0)
            {
                indexFound = i;
                sqrDist    = dist;
            }
            else if (dist < sqrDist)
            {
                sqrDist    = dist;
                indexFound = i;
            }
            firstIndex++;
        }

        if (indexFound == -1)
        {
            //Debug.LogWarning("nothing found");
            return(ExtVector3.GetNullVector());
        }
        return(arrayPos[indexFound]);
    }