/// <summary>Returns the unit in given unit list that is closest to the given formation position</summary>
        private Unit ClosestUnitToFormationPosition(List<Unit> units, FormationPosition position)
        {
            float closestSqrMagnitude = float.MaxValue;
            Unit closest = null;
            foreach (Unit unit in units)
            {
                float sqrmagnitude = (unit.transform.position - position.Point(false)).sqrMagnitude;
                if (sqrmagnitude < closestSqrMagnitude)
                {
                    closest = unit;
                    closestSqrMagnitude = sqrmagnitude;
                }
            }

            return closest;
        }
Beispiel #2
0
 /// <summary>Sets the destination of the agent to move towards the assigned position</summary>
 public void MoveTowardsAssignedPosition()
 {
     agent.SetDestination(assignedPosition.Point(false));
 }