Check closest unit

Status
Not open for further replies.
There's plenty of threads on this already, but here's the idea:
  • Actions
    • Set Variable Position1 = (Position of (Triggering unit))
    • Set Variable ClosestUnit = No unit
    • Set Variable ClosestDistance = 99999.00
    • Set Variable ClosestGroup = (Units that are allied with Owner of (Triggering unit) excluding (Triggering unit), Dead units, etc)
    • Unit Group - Pick every unit in ClosestGroup and do Actions
      • Loop - Actions
        • Set Variabe Position2 = (Position of (Picked unit))
        • Set Variable CurrentDistance = (Distance between Position 1 and Position2)
        • If all conditions are true then do (Actions)
          • If - Conditions
            • CurrentDistance Less than ClosestDistance
          • Then - Actions
            • Set Variable ClosestUnit = (Picked unit)
            • Set Variable ClosestDistance = CurrentDistance
          • Else - Actions
    • Unit - Kill ClosestUnit <-- just an example
After the Loop is completely finished you will have your ClosestUnit. Don't forget to clean up the memory leaks.
 
Last edited:
Status
Not open for further replies.
Back
Top