• 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.

Get closest unit towards my unit?

Status
Not open for further replies.
Level 20
Joined
Jan 6, 2008
Messages
2,627
Hello, ive tried to solve this problem for a time now, but i cant manage to do it.

i want to make a shooter map, as everyone have seen (i guess lol).
and i want it to damage the unit which my unit is facing and then stop continuing searching for the nearest one.

like
O = targets
X = my unit (Facing north)
O = target "loosing" health
OOO
OOO
OOO
OXO
OOO

just an example

OOO
OOO
O..O
OXO
OOO

like that =)

Solutions anyone?
 
Level 20
Joined
Jan 6, 2008
Messages
2,627
Bump: This is how far ive gotten, Im stuck on getting the units in position Of my missile!

  • ShootCLICK
    • Events
      • UI - Player Any Player clicks Left mouse button Down.
    • Local Variables
    • Conditions
      • moveUp == false
      • moveDown == false
    • Actions
      • Trigger - Turn ShootLoop On
  • ShootRELEASE
    • Events
      • UI - Player Any Player clicks Left mouse button Up.
    • Local Variables
    • Conditions
    • Actions
      • Trigger - Turn ShootLoop Off
      • Animation - Play Stand animation for (Actor for UNIT) as Default, using Non Looping options and Default Time blend time
  • ShootLoop
    • Events
      • Timer - Every 1.0 seconds of Game Time
    • Local Variables
      • U = No Unit <Unit>
    • Conditions
      • ((Current trigger) is on) == true
    • Actions
      • Animation - Play Attack animation for (Actor for UNIT) as Default, using Non Looping options and Default Time blend time
      • General - Wait 0.2 Game Time seconds
      • Sound - Play Ghost_AttackImpact for (All players) on UNIT with Z offset 0.0 (at 100.0% volume, skip the first 0.0 seconds)
      • Actor - Attach Ghost Attack Launch to Weapon on UNIT
      • Unit - Create 1 Weapon - Banshee for player 1 at (Position of UNIT) facing (Facing of UNIT) degrees (No Options)
      • Variable - Set U = (Last created unit)
      • General - Wait 2.0 Game Time seconds
      • Unit - Remove U from the game
  • ShootLoop2
    • Events
      • Timer - Every 0.05 seconds of Game Time
    • Local Variables
      • UG = (Units in (Weapon - Banshee units in (Entire map) owned by player Any Player matching Excluded: Dead, Hidden, with at most Any Amount) owned by player 1, with at most Any Amount) <Unit Group>
      • U = No Unit <Unit[2]>
    • Conditions
    • Actions
      • Unit Group - Pick each unit in UG and do (Actions)
        • Actions
          • Unit - Order (Picked unit) to ( Move targeting ((Position of (Picked unit)) offset by 5.0 towards (Facing of (Picked unit)) degrees)) (Replace Existing Orders)
          • Variable - Set U[1] = (Picked unit)
          • ------- Stuck here -------
          • Unit - Kill U[1]
          • Unit - Set (Picked unit) Life to (((Picked unit) Life (Current)) - 50.0)
          • Debug - Display "BOOM, unit attacked =)" as debug output using Type 1, and Do display it in the game window
 
Level 3
Joined
Jul 12, 2007
Messages
50
If it is possible to get the X and Y position of units, I would say use the cycle through them using the distance formula... I am not 100% sure how you would do that in the GUI editor though.
 
Level 13
Joined
Feb 28, 2007
Messages
477
Many ways.

First thing that comes to mind (GUI): Loop through all of the units in a region facing forward from where you want to pick them, checking the distance from that unit to the caster. Store these values in a real array, first dimension, and have a separate unit array with the same order to store which unit goes with which distance. Then loop through those real values, using the min function to filter out the smallest one(s), ranking each in the corresponding second dimension of the real array. After that loop runs, you now have a heirarchial list of each unit's position in the line from the caster.

You can use the above post's method if you only want one unit. My method lets you do stuff like piercing, etc.
 
Level 14
Joined
Mar 4, 2009
Messages
1,156
dunno why but i posted this before and come back and it was not here

-this is from WE but it can show you how to get nearest unit to some position
-you probably do not need to set and remove locations/unit groups when used
-the UNITGROUP will need to be units units within < X Range > of POINT[0] matching condition < ... and unit is in front of your unit - this condition can be made with degree conditions or maybe find some other way >

  • GetNearestUnit
    • Events
    • < your Event >
    • Conditions
    • < your Condition >
    • Actions
      • Set POINT[0] = < Your Position >
      • Set UNITGROUP = < Your Units that you want to pick >
      • Set REAL = 999999.00
      • Unit Group - Pick every unit in UNITGROUP and do (Actions)
        • Loop - Actions
          • Set POINT[1] = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between POINT[0] and POINT[1]) Less than REAL
            • Then - Actions
              • Set REAL = (Distance between POINT[0] and POINT[1])
              • Set NearestUnit = (Picked unit)
          • Custom script: call RemoveLocation(udg_POINT[1])
          • Else - Actions
      • Custom script: call RemoveLocation(udg_POINT[0])
      • -------- the NearestUnit is nearest unit from POINT[0] that is in UNITGROUP --------
what this does is picking every unit to unit group and sets the variable REAL to distance from POINT[0] to position of Picked Unit,now if it finds unit more near than REAL is will set REAL to his distance

for example:
(Distance is distance from unit to point)

UNIT 1 - Distance 100 - is will set REAL to 100 because this is the first picked unit
UNIT 2 - Distance 300 - it will skip this unit because distance is bigger than REAL
UNIT 3 - Distance 70 - it will set REAL to distance because distance is smaller than REAL
UNIT 4 - Distance 150 - it will skip this unit because distance is bigger than REAL
UNIT 5 - Distance 300 - it will skip this unit because distance is bigger than REAL
UNIT 6 - Distance 20 - it will set REAL to distance because distance is smaller than REAL
UNIT 7 - Distance 25 - it will skip this unit because distance is bigger than REAL
 
Status
Not open for further replies.
Top