HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Closest unit

07-21-2004, 04:59 PM#1
mosarani
What's the best equivalent of 'unit comes within range of unit' that can use a global variable as the unit whom a unit is coming in range of. I'm working on a bouncing missile sort of thing. Whenever a unit comes within 50 range of it or so It should bounce off in a different trajectory. I have a periodic trigger that gets turned on that could detect all nearby units every .5 seconds ( I worry about lag in a big map if i make it more frequent) but that still doesn't help me find the closest unit. This could be flying into a group of enemy units and unless I know the closest one, it's gonna fly off in a really ugly looking direction. How can I know which unit is closest to this unit variable?
07-21-2004, 05:08 PM#2
Norwegian
I don't know about that...

Wouldn't it just be easyer to make a unit with almost no damage, and the range you want it to, define the target for you? Might require a bit of messing around, but I think that it might be easyer. <unit comes within (range) of (unit)> is a real bitch.
07-21-2004, 08:47 PM#3
Shimrra
Unfortunately, Blizzard did not include a closest unit function, but you could technically replicate it; though it might cause some lag if done at a rapid rate...

What I would suggest is that you do something like this:
Code:
Actions
    Unit group - Pick a random 1 unit from (Units within 50 of unit) and set (Picked unit) to variable UnitVar
    If\Then\Else
        If
            UnitVar is equal to No unit
        Then
            Unit group - Pick a random 1 unit from (Units within 100 of unit) and set (Picked unit) to variable UnitVar
        Else
            Do missile bounce actions

YOu could then just keep increasing the in range number until it either hit a maximum range or eventually found a unit. It migh tnot get the absolute closest unit if there are many, but if the range differemce is small enough, there won't be an overly large visual difference. Good luck!

~Shimrra
07-21-2004, 08:49 PM#4
mosarani
Quote:
Originally Posted by Norwegian
I don't know about that...

Wouldn't it just be easyer to make a unit with almost no damage, and the range you want it to, define the target for you? Might require a bit of messing around, but I think that it might be easyer. <unit comes within (range) of (unit)> is a real bitch.

I don't see any way to 'stick' this attacking unit to my projectile. The projectile can't have the attack for a variety of reasons. Maybe I should have posted this in ai/jass vault. The only thing I can think of is making a loop like check units in concentric circles starting outwards from projectile, but that would be very laggy.
07-21-2004, 10:34 PM#5
mosarani
I think I see a way that may work but I'd still like some help with somehting. How would you go about triggering that old physics law (angle of incidence = angle of reflection) into a trigger where the direction of the projectile is controlled by a real variable for degres?
07-21-2004, 10:39 PM#6
Shimrra
Isn't the opposite? If it's the same angle, then the object would always bounce back to the source. If the object comes in at 45 degrees, wouldn't it reflect at 135?