Answers for "unity take average of all vector3"

0

unity take average of all vector3

//Credit: Grofie - https://answers.unity.com/questions/164257/find-the-average-of-10-vectors.html
 
 private Vector3 GetMeanVector(Vector3[] positions)
 {
     if (positions.Length == 0)
         return Vector3.zero;
     float x = 0f;
     float y = 0f;
     float z = 0f;
     foreach (Vector3 pos in positions)
     {
         x += pos.x;
         y += pos.y;
         z += pos.z;
     }
     return new Vector3(x / positions.Length, y / positions.Length, z / positions.Length);
 }
Posted by: Guest on August-22-2021

Browse Popular Code Answers by Language