673 posts Sunny Singapore, the lil' red dot joined
#1
nearest hero
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.
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!
673 posts Sunny Singapore, the lil' red dot joined
#3
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.
Well, I don't really get what you want. The code I showed you just detects the closest hero around UUNIT, nothing else. Then that unit is stored into the variable and you can use it by the variable. ~Daelin
673 posts Sunny Singapore, the lil' red dot joined
#5
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?