View Single Post
Old 01-31-2010, 08:53 PM   #8
Themerion
Brahms-fan
 
Themerion's Avatar
 
Join Date: Jan 2006
Posts: 642

Submissions (2)

Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)

Default

Quote:
I'm trying to find closest unit to a certain point.

Here's an outline for how it's done. It's made to be simple, read comment on (meaningless? :P) optimizations below.

Trigger:
Set CertainPoint = (Center of (Playable Map Area))
Set TempReal = 500
Set TempUnit = No Unit
Collapse Unit Group - Pick All units in 500 from CertainPoint
Collapse Loop
Collapse If
Collapse Conditions
Distance Between (Certain Point) and (Position of (Picked Unit)) less than TempReal
Collapse Actions
Set TempUnit = (Picked Unit)
Set TempReal = Distance Between (Certain Point) and (Position of (Picked Unit))

Collapse if TempUnit not equal to No Unit
--- Voila, the closest unit was TempUnit ---

Once you understand this outline, you should probably optimize it by storing "Distance Between..." as a variable (so you won't have to check multiple times for the same unit). You should also take care of the point-leaks, and the unit group leak.
__________________
Submissions::
(v)JASS Tutorial
Covers how to make fast and safe coding for common tasks in vJASS/JASS.
Creep Respawn System
It has never been easier to respawn creep groups...
Themerion is offline   Reply With Quote