public void CalculateAndExecuteBehaviors() { if (Movers.Count >= MinimumGroupSize) { for (i = 0; i < Movers.Count; i++) { Move mover = Movers [i]; GroupPosition += mover.Body.Position; } GroupPosition /= Movers.Count; biggestSqrDistance = 0; for (i = 0; i < Movers.Count; i++) { currentSqrDistance = Movers [i].Body.Position.SqrDistance (GroupPosition.x, GroupPosition.y); if (currentSqrDistance > biggestSqrDistance) { currentDistance = FixedMath.Sqrt (currentSqrDistance); /* DistDif = currentDistance - Radius; if (DistDif > MaximumDistDif * MoversCount / 128) { ExecuteGroupIndividualMove (); return; }*/ biggestSqrDistance = currentSqrDistance; Radius = currentDistance; } } if (GroupPosition.SqrDistance (Destination.x, Destination.y) < (biggestSqrDistance * 5 / 4)) { ExecuteGroupIndividualMove (); return; } GroupDirection = Destination - GroupPosition; for (i = 0; i < Movers.Count; i++) { Move mover = Movers [i]; mover.Destination = mover.Body.Position + GroupDirection; mover.IsFormationMoving = true; mover.closingDistanceMultiplier = FixedMath.One * 2 / 5; mover.StartMove (); } } else { for (i = 0; i < Movers.Count; i++) { Move mover = Movers [i]; mover.closingDistanceMultiplier = FixedMath.One / 4; mover.Destination = Destination; mover.IsFormationMoving = false; mover.StartMove (); } } }