• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Get Group Center

Status
Not open for further replies.

ISL

ISL

Level 13
Joined
Nov 7, 2014
Messages
238
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.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,204
There are statistical measures for how spread out samples are. Instead of trying to reinvent the wheel I suggest using one.

One such measure is standard deviation. If the group of units has a large standard deviation of their position samples then they are spread out. Of course others might exist.
 
  • Like
Reactions: ISL
Status
Not open for further replies.
Top