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: 339

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.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top