HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Nearest unit

02-04-2006, 12:39 PM#1
Thunder_Eye
Can someone tell me an easy way to check what unit within 500 (or something) is nearest the caster?

I know this has been asked before but I dont have time to search it up.
02-04-2006, 12:56 PM#2
Vexorian
Get the unit whose distance to the caster is the minimum of all the distances you get
02-04-2006, 06:07 PM#3
Thunder_Eye
So.. how would I do that in trigger?
would I have to loop it like first 10, 20, 30, 40 etc. or is there any easier way?
02-04-2006, 06:10 PM#4
PCPharaoh
Pick every unit in 500 of caster, and calculate their distance to the caster. Whoever has the shortest distance is your unit.
02-04-2006, 06:13 PM#5
Thunder_Eye
Well I dont get how to do the check, I'll need a variable right?

This works?
Trigger:
Unit Group - Pick every unit in (Units within 1000.00 of (Position of Peasant 0000 <gen>) matching (((Matching unit) Not equal to Peasant 0000 <gen>) and (((Matching unit) is dead) Equal to False))) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Unit Equal to No unit
Collapse Then - Actions
Set Unit = (Picked unit)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Distance between (Position of Peasant 0000 <gen>) and (Position of (Picked unit))) Less than (Distance between (Position of Peasant 0000 <gen>) and (Position of Unit))
Collapse Then - Actions
Set Unit = (Picked unit)
Else - Actions
gonna test it now
and YES I know it leaks alot.

EDIT: Well it works sometimes :S

EDIT2: Ok its fixed, had to check if the picked unit was dead or not, thx for the help.
02-04-2006, 06:26 PM#6
PCPharaoh
That seems like it would work to me. When exactly does it work and not work?

Opps. Posted before your edit2. Nevermind. :P