Example #1
0
 //TODO Optimise the hell out of this
 void UpdateVel()
 {
     timeRecalc += Time.deltaTime;
     if (parentGen.islandMoveTime > 0 && timeRecalc >= parentGen.islandMoveIntervals)
     {
         pseudoVel = Vector3.zero;
         foreach (IslandGen i in parentGen.GetAllIslands())
         {
             float distance = Vector3.Distance(GetPosition(), i.GetPosition()); //TODO Change to squared to save preformance
             distance = Mathf.Max(1, distance);
             if (distance < neglibleDistance)
             {
                 Vector3 direction = (GetPosition() - i.GetPosition()) / distance;
                 if (distance != 0)
                 {
                     Vector3 thisForce = i.GetArea() / (Mathf.Pow(distance, 3f)) * direction;
                     pseudoVel += thisForce;
                 }
             }
         }
         timeRecalc = 0;
     }
     if (parentGen.islandMoveTime > 0)
     {
         transform.position += forceConstant * pseudoVel * Time.deltaTime;
     }
 }