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

Distance between units

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
The distence between 2 units is the same as the distance between 2 points.

To do that you need to run a mathematical formula to find the hypotnuse of the right angled triangle between the 2 points.

it is basicly the square root of the square of the distance between X1 X2 and the square of the distance between Y1 and Y2 added together.

SquareRoot((X1-X2)(X1-X2)+(Y1-Y2)(Y1-Y2))
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
You missed squaring it, super :p

SquareRoot(deltaX * deltaX + deltaY * deltaY )

And in GUI, it's as RedBlade said. However, you'll want to clean up the leaks, or you'll get slowness/delay issues after awhile.

Eg.

  • Set loc = (Position of (Triggering Unit))
  • -------- do something with loc --------
  • Custom script: call RemoveLocation(udg_loc)
where loc is a global point variable
 
Level 2
Joined
May 24, 2007
Messages
12
Well, to actually answer the question he asked...

Action
- Set IntVar = (Integer((Distance between (Position of [Unit1]) and (Position of [Unit2]))))
 
Level 5
Joined
Jul 17, 2006
Messages
145
Distance between two units can be stored in a real variable. Good luck finding it, considering you couldnt even find the proper forum which was right above this one.

Moved.

did i post this in the Map Development forum?
O___O my bad, at least i thought i clicked on the world editor forum XD

and yea thx to those who helped...
 
Status
Not open for further replies.
Top