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

[Solved] Get Group Center

Status
Not open for further replies.

ISL

ISL

Level 14
Joined
Nov 7, 2014
Messages
242
Pick every unit in your unit group and sumarize their X and Y locations
Then divide both sums you just got by the total group size

And there you go! You just got X and Y values for the point which is the center of your unit group
Hope it helps :)
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Why not:

get highest X/Y value
get lowest X/Y value

(highest - lowest) / 2 = center

Hmmmm, this would support bigger unit groups, but I don't think that the difference matters for practical purposes, unless you are making a 1 vs 1 million in war3... with actually 1 mil units on screen...

@xISLx 's method is simpler, works faster and is more accurate.

PS: Although, I like yours more :D
 
Hmm, to be honest I imagined this like Chaosy did with drawing rectangle example.
It supposed to be used in a game as a check if units are to stretched, so getting a center point with average distance to this center is what I'm trying to achieve.
On the other hand, looking at IcemanBo example maybe it will be smarter to just order this one unit (on point 100/100) to join the others? I have to think about this, however solutions are given. Thanks so much guys.
 
Status
Not open for further replies.
Top