How to get the exact mid point between several points.

Solu9

You can change this now in User CP.
Reaction score
216
I've got four units the player can control and I would like the camera to be centered in the intersection between all four of them.

I have attached a file in an attempt to visualize what I mean.
The four black spots are the units and the red spot is the point I need. Well more or less, since that's the problem.
How can I calculate the position of the red spot?

I hope you understand what I need.
 

Attachments

  • Some point.jpg
    Some point.jpg
    22.4 KB · Views: 343

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Find the maximum x-coordinate and minimum x-coordinate, then average them? Then repeat for y-coordinates.
 

Solu9

You can change this now in User CP.
Reaction score
216
Hm yeah I have been trying to fizzle with your suggestion and this is what I came up with.
Now don't laugh at the execution :p

Trigger:
  • Run Camera Single Copy
Trigger:
  • <s>Events</s>
    • <s>Time - Every 0.10 seconds of game time</s>
    • <s>Conditions</s>
    • <s>Actions</s>
    • <s>-------- --------------------------- Get X and Y coordinates --------------------------- --------</s>
    • <s>Set pSquardPoint = (Position of Orc Elite 0003 &lt;gen&gt;)</s>
    • <s>Set rXcoor[1] = (X of pSquardPoint)</s>
    • <s>Set rYcoor[1] = (Y of pSquardPoint)</s>
    • <s>Custom script: call RemoveLocation (udg_pSquardPoint)</s>
    • <s>Set pSquardPoint = (Position of Orc Marine 0006 &lt;gen&gt;)</s>
    • <s>Set rXcoor[2] = (X of pSquardPoint)</s>
    • <s>Set rYcoor[2] = (Y of pSquardPoint)</s>
    • <s>Custom script: call RemoveLocation (udg_pSquardPoint)</s>
    • <s>Set pSquardPoint = (Position of Orc Sniper 0010 &lt;gen&gt;)</s>
    • <s>Set rXcoor[3] = (X of pSquardPoint)</s>
    • <s>Set rYcoor[3] = (Y of pSquardPoint)</s>
    • <s>Custom script: call RemoveLocation (udg_pSquardPoint)</s>
    • <s>Set pSquardPoint = (Position of Orc Rocker Hunter 0008 &lt;gen&gt;)</s>
    • <s>Set rXcoor[4] = (X of pSquardPoint)</s>
    • <s>Set rYcoor[4] = (Y of pSquardPoint)</s>
    • <s>Custom script: call RemoveLocation (udg_pSquardPoint)</s>
    • <s>-------- --------------------------- Get min/max points --------------------------- --------</s>
    • <s>Trigger - Run Run X &lt;gen&gt; (checking conditions)</s>
    • <s>Trigger - Run Run Y &lt;gen&gt; (checking conditions)</s>
    • <s>-------- --------------------------- Get Average --------------------------- --------</s>
    • <s>Set rXcoorReal_max = ((rXcoorReal_min + rXcoorReal_max) / 2.00)</s>
    • <s>Set rYcoorReal_max = ((rYcoorReal_min + rYcoorReal_max) / 2.00)</s>
    • <s>-------- --------------------------- Pan Camera --------------------------- --------</s>
    • <s>Set pXYcoorFinal = (Point(rXcoorReal_max, rYcoorReal_max))</s>
    • <s>Camera - Pan camera for Player 1 (Red) to pXYcoorFinal over 0.30 seconds</s>
    • <s>Custom script: call RemoveLocation (udg_pXYcoorFinal)</s>
    • <s>-------- --------------------------- Reset XY reals --------------------------- --------</s>
    • <s>Set rXcoorReal_min = 0.00</s>
    • <s>Set rXcoorReal_max = 0.00</s>
    • <s>Set rYcoorReal_min = 0.00</s>
    • <s>Set rYcoorReal_max = 0.00</s>


Trigger:
  • Run X
Trigger:
  • <s>Events</s>
    • <s>Conditions</s>
    • <s>Actions</s>
    • <s>For each (Integer A) from 1 to 4, do (Actions)</s>
    • <s>Loop - Actions</s>
    • <s>If (All Conditions are True) then do (Then Actions) else do (Else Actions)</s>
    • <s>If - Conditions</s>
    • <s>rXcoor[(Integer A)] Greater than or equal to rXcoorReal_max</s>
    • <s>Then - Actions</s>
    • <s>Set rXcoorReal_max = rXcoor[(Integer A)]</s>
    • <s>Else - Actions</s>
    • <s>If (All Conditions are True) then do (Then Actions) else do (Else Actions)</s>
    • <s>If - Conditions</s>
    • <s>rXcoor[(Integer A)] Less than or equal to rXcoorReal_min</s>
    • <s>Then - Actions</s>
    • <s>Set rXcoorReal_min = rXcoor[(Integer A)]</s>
    • <s>Else - Actions</s>


Trigger:
  • Run Y
Trigger:
  • <s>Events</s>
    • <s>Conditions</s>
    • <s>Actions</s>
    • <s>For each (Integer B) from 1 to 4, do (Actions)</s>
    • <s>Loop - Actions</s>
    • <s>If (All Conditions are True) then do (Then Actions) else do (Else Actions)</s>
    • <s>If - Conditions</s>
    • <s>rYcoor[(Integer B)] Greater than or equal to rYcoorReal_max</s>
    • <s>Then - Actions</s>
    • <s>Set rYcoorReal_max = rYcoor[(Integer B)]</s>
    • <s>Else - Actions</s>
    • <s>If (All Conditions are True) then do (Then Actions) else do (Else Actions)</s>
    • <s>If - Conditions</s>
    • <s>rYcoor[(Integer B)] Less than or equal to rYcoorReal_min</s>
    • <s>Then - Actions</s>
    • <s>Set rYcoorReal_min = rYcoor[(Integer B)]</s>
    • <s>Else - Actions</s>


Now the average X location works like a charm. The camera slides from right to left and left to right according to where the four units are.
But the average Y location does not.
The camera will never travel up or down and I can't figure out why.
I have been looking myself blind on the triggers.

Edit:
Hmm. When the four units is spread around the center point of the map the camera can move in all directions it seems.
But another issue occurs.
The camera will only slide so far in either direction. It's like there is some kind of diminishing return.
I suspect it is "Get Average Location" in the first trigger which causes this, but I honestly don't know.

Edit2:
Nevermind I got it to work. I don't know why though.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Nevermind I got it to work. I don't know why though.

Glad I could help :p

EDIT: Also, there's a Max and Min function under Math that you could use to shorten the triggers a bit. I believe they use the same method, but it saves some of the time you might have used to build this trigger.
 

Solu9

You can change this now in User CP.
Reaction score
216
That's the problem with the edit function. It was by accident I saw you edit.

Anyway. I have never really used those math functions other than the standard and Mod.
But I can see the point in using what you are suggesting here :)
And I guess it just straight forward.
 

bajaist

Member
Reaction score
4
I don't think that you can use only min and max, since square that these units create is irregular. You should probably use mean of all 4 x and y coordinates.
 

Solu9

You can change this now in User CP.
Reaction score
216
Actually I ended up with not using the min,max functions. Main reason is that the triggers work as they are right now and I don't want to mess too much around with them.

Anyway.

Trigger:
  • Count Selected Units
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer B) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set booUnitIsSelected[(Integer B)] = False
      • Set ugSelectedGroup = (Units currently selected by Player 1 (Red))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Random unit from ugSelectedGroup)) Equal to Player 1 (Red)
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in ugSelectedGroup) Greater than 1
            • Then - Actions
              • Set uSelectedUnit = No unit
              • For each (Integer A) from 1 to 4, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (uSquardMember[(Integer A)] is in ugSelectedGroup) Equal to True
                    • Then - Actions
                      • Set booUnitIsSelected[(Integer A)] = True
                    • Else - Actions
              • Trigger - Run Run Camera Group &lt;gen&gt; (checking conditions)
            • Else - Actions
              • Set uSelectedUnit = (Random unit from ugSelectedGroup)
              • Trigger - Run Run Camera Single &lt;gen&gt; (checking conditions)
        • Else - Actions
      • Custom script: call DestroyGroup (udg_ugSelectedGroup)


Trigger:
  • Run Camera Single
    • Events
    • Conditions
    • Actions
      • Set pXYcoorFinal = (Position of uSelectedUnit)
      • Camera - Pan camera for Player 1 (Red) to pXYcoorFinal over 0.30 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Distance to target to rCameraDistance over 0.20 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Angle of attack to 340.00 over 0.00 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Height Offset to 200.00 over 0.50 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Rotation to rCameraRotation[iCameraRotation] over 0.50 seconds
      • Custom script: call RemoveLocation (udg_pXYcoorFinal)


Trigger:
  • Run Camera Group
    • Events
    • Conditions
    • Actions
      • -------- --------------------------- Get X and Y coordinates --------------------------- --------
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booUnitIsSelected[(Integer A)] Equal to True
            • Then - Actions
              • Set pSquardPoint = (Position of uSquardMember[(Integer A)])
              • Set rXcoor[(Integer A)] = (X of pSquardPoint)
              • Set rYcoor[(Integer A)] = (Y of pSquardPoint)
              • Custom script: call RemoveLocation (udg_pSquardPoint)
            • Else - Actions
      • -------- --------------------------- Get min/max points --------------------------- --------
      • Trigger - Run Run X &lt;gen&gt; (checking conditions)
      • Trigger - Run Run Y &lt;gen&gt; (checking conditions)
      • -------- --------------------------- Get Average --------------------------- --------
      • Set rXcoorReal_NewPoint = ((rXcoorReal_min + rXcoorReal_max) / 2.00)
      • Set rYcoorReal_NewPoint = ((rYcoorReal_min + rYcoorReal_max) / 2.00)
      • -------- --------------------------- Pan Camera --------------------------- --------
      • Set pXYcoorFinal = (Point(rXcoorReal_NewPoint, rYcoorReal_NewPoint))
      • Camera - Pan camera for Player 1 (Red) to pXYcoorFinal over 0.30 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Distance to target to rCameraDistance over 0.20 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Angle of attack to 340.00 over 0.00 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Height Offset to 200.00 over 0.50 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Rotation to rCameraRotation[iCameraRotation] over 0.50 seconds
      • Custom script: call RemoveLocation (udg_pXYcoorFinal)


Trigger:
  • Run X
    • Events
    • Conditions
    • Actions
      • Set rXcoorReal_max = -999999.00
      • Set rXcoorReal_min = 999999.00
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booUnitIsSelected[(Integer A)] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rXcoor[(Integer A)] Greater than or equal to rXcoorReal_max
                • Then - Actions
                  • Set rXcoorReal_max = rXcoor[(Integer A)]
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rXcoor[(Integer A)] Less than or equal to rXcoorReal_min
                • Then - Actions
                  • Set rXcoorReal_min = rXcoor[(Integer A)]
                • Else - Actions
            • Else - Actions


Trigger:
  • Run Y
    • Events
    • Conditions
    • Actions
      • Set rYcoorReal_max = -999999.00
      • Set rYcoorReal_min = 999999.00
      • For each (Integer B) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booUnitIsSelected[(Integer B)] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rYcoor[(Integer B)] Greater than or equal to rYcoorReal_max
                • Then - Actions
                  • Set rYcoorReal_max = rYcoor[(Integer B)]
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rYcoor[(Integer B)] Less than or equal to rYcoorReal_min
                • Then - Actions
                  • Set rYcoorReal_min = rYcoor[(Integer B)]
                • Else - Actions
            • Else - Actions
 

bajaist

Member
Reaction score
4
Sorry for the long response.
Anyway, as far as i can see unless your map is bigger than 999999.00 x 999999.00, camera will always pan to exact same spot, center of the map, or i am missing something.
But if it works for you, then i guess all is fine. :)
 

Solu9

You can change this now in User CP.
Reaction score
216
The only reason I set those value so high is exactly because they are way bigger than the map.
Fx. if I used -2000 for the max X value.
A unit could easily be at -5000 X and would therefore be less than, and not greater than, and be ignored in the point calculation.

At least I believe that's the reason I use those large numbers. I can't remember but I think that makes sense :p
 

denmax

You can change this now in User CP.
Reaction score
155
Edit: Nevermind, i should have read the post more. You already solved it xD

I was talking about centroid of liness and shez
 

bajaist

Member
Reaction score
4
I thought so. But then you don't need to calculate it, since min and max are always 999999.00, (min + max) / 2 is always 0, so result is always (0, 0) coordinates.
 

Solu9

You can change this now in User CP.
Reaction score
216
The numbers are reversed.
Max X checks if it is greater than -999999.00, it always will be.
Min X checks if it is less than 999999.00, it always will be.

The numbers here are set so they will always only act as a placeholders until actual usable data is set.
 

Solu9

You can change this now in User CP.
Reaction score
216
Here the triggers are executed.

Use the arrow keys to change distance and angle.
And try to split up the different units. Fx. order two to go far away and use the portraits to rotate to other units.

Edit:
Space Orc models used are created by Frankster from Hive Workshop.
 

bajaist

Member
Reaction score
4
It needs some getting used to, but it looks really nice. I've sent them all in different directions, and camera performs exactly as it should. :)
 

Solu9

You can change this now in User CP.
Reaction score
216
Yeah it is quite funky to begin with.
What I like most about it is the way it behaves when selecting groups of units :)

Glad you like it.
Guess I should use it for something.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top