• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

nearest hero

Status
Not open for further replies.
Level 10
Joined
Jul 2, 2004
Messages
690
im making a 3rd person view map and i was wondering how do you pick the nearest enemy hero? for spells or in this case, make your hero face the nearest enemy hero.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
You will need an integer, and a unit variable and here is the code:

set intvariable = 0
Pick up every unit within x range matching conditions ((Matching Unit) is a hero equal to true)) and do actions
-> If (Distance Between (Position of UUNIT) and (Position of (Picked Unit)) is less than intvariable or intvariable == 0 then do
set intvariable = Distance Between (Position of Unit) and (Position of (Picked Unit))
set unitvariable = (Picked Unit)

And at the end, the unitvariable is your unit. Change x with the range in which you may pick the closest hero and the UUNIT with the unit around which you pick the closest target. Have a nice day!

~Daelin
 
Level 10
Joined
Jul 2, 2004
Messages
690
uh... i dont really get the "If (Distance Between (Position of UUNIT) and (Position of (Picked Unit)) is less than intvariable or intvariable == 0" part. do i make a new trigger to make the casting unit of the spell face unitviarable? sorry for the inconvenience.
 
Level 10
Joined
Jul 2, 2004
Messages
690
actually the spell was to make the unit face the nearest enemy hero, as the map would be in 1st/3rd person view. so that the player can easily turn the camera.

back to the trigger. so i create trigger using the one you gave me to detect the nearest enemy hero and a new one to make the unit turn to face the unitvariable right?
 
Status
Not open for further replies.
Top