Solved Finding center point of two locations

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Veraid

Member
Feb 8, 2017
25
8
3
28
Skript Version: Skript 2.2 (dev32c)
Skript Author: Bensku
Minecraft Version: 1.12.2


code_language.skript:
command /test:
  trigger:
    set {_loct} to {vsk_session-temporary::%uuid of player%::p1}
    set x coord of {_loct} to x coord of {vsk_session-temporary::%uuid of player%::p1} + x coord of {vsk_session-temporary::%uuid of player%::p2}
    set z coord of {_loct} to z coord of {vsk_session-temporary::%uuid of player%::p1} + z coord of {vsk_session-temporary::%uuid of player%::p2}
    set y coord of {_loct} to y coord of {vsk_session-temporary::%uuid of player%::p1} + y coord of {vsk_session-temporary::%uuid of player%::p2}
    loop 100 times:
      set {_loc} to direction from player to {_loct}
      push player {_loc} at speed 0.5
      wait 2 ticks

Can someone clever please just give me some code to find the exact center between one location and another I'm not smart enough for it and rusty with Skript
 
Skript Version: Skript 2.2 (dev32c)
Skript Author: Bensku
Minecraft Version: 1.12.2


code_language.skript:
command /test:
  trigger:
    set {_loct} to {vsk_session-temporary::%uuid of player%::p1}
    set x coord of {_loct} to x coord of {vsk_session-temporary::%uuid of player%::p1} + x coord of {vsk_session-temporary::%uuid of player%::p2}
    set z coord of {_loct} to z coord of {vsk_session-temporary::%uuid of player%::p1} + z coord of {vsk_session-temporary::%uuid of player%::p2}
    set y coord of {_loct} to y coord of {vsk_session-temporary::%uuid of player%::p1} + y coord of {vsk_session-temporary::%uuid of player%::p2}
    loop 100 times:
      set {_loc} to direction from player to {_loct}
      push player {_loc} at speed 0.5
      wait 2 ticks

Can someone clever please just give me some code to find the exact center between one location and another I'm not smart enough for it and rusty with Skript

code_language.skript:
Set {_loc1} To
Set {_loc2} To
Set {_x1} To x-coordinate of {_loc1}
Set {_y1} To y-coordinate of {_loc1}
Set {_z1} To z-coordinate of {_loc1}
Set {_x2} To x-coordinate of {_loc2}
Set {_y2} To y-coordinate of {_loc2}
Set {_z2} To z-coordinate of {_loc2}

Set {_newx} To {{_x2} - {_x1}) / 2
Set {_newy} To {{_y2} - {_y1}) / 2
Set {_newz} To {{_z2} - {_z1}) / 2

Add {_newx} To x-coordinate of {_loc1}
Add {_newy} To y-coordinate of {_loc1}
Add {_newz} To z-coordinate of {_loc1}
Set {_middle} To {_loc1}
 
The point halfway between two 3-dimensional points is the addition of their axes divided by 2. So, it should be:
code_language.skript:
set {_midpoint-x} to round(({_point-1}'s x-pos + {_point-2}'s x-pos)/2) + .5
set {_midpoint-y} to round(({_point-1}'s y-pos + {_point-2}'s y-pos)/2) + .5
set {_midpoint-z} to round(({_point-1}'s z-pos + {_point-2}'s z-pos)/2) + .5

set {_midpoint} to location({_midpoint-x}, {_midpoint-y}, {_midpoint-z}, {_point-1}'s world)
I added 0.5 to the x, y and z axis so it's at the center of the block and not in the bottom corner.
 
The point halfway between two 3-dimensional points is the addition of their axes divided by 2. So, it should be:
code_language.skript:
set {_midpoint-x} to round(({_point-1}'s x-pos + {_point-2}'s x-pos)/2) + .5
set {_midpoint-y} to round(({_point-1}'s y-pos + {_point-2}'s y-pos)/2) + .5
set {_midpoint-z} to round(({_point-1}'s z-pos + {_point-2}'s z-pos)/2) + .5

set {_midpoint} to location({_midpoint-x}, {_midpoint-y}, {_midpoint-z}, {_point-1}'s world)
I added 0.5 to the x, y and z axis so it's at the center of the block and not in the bottom corner.

Great just tried this code out
code_language.skript:
command /center:
  trigger:
    set {_midpoint} to {vsk_session-temporary::%uuid of player%::p1}
    set x coord of {_midpoint} to round(({vsk_session-temporary::%uuid of player%::p1}'s x-pos + {vsk_session-temporary::%uuid of player%::p2}'s x-pos)/2) + .5
    set y coord of {_midpoint} to round(({vsk_session-temporary::%uuid of player%::p1}'s y-pos + {vsk_session-temporary::%uuid of player%::p2}'s y-pos)/2) + .5
    set z coord of {_midpoint} to round(({vsk_session-temporary::%uuid of player%::p1}'s z-pos + {vsk_session-temporary::%uuid of player%::p2}'s z-pos)/2) + .5
    loop 100 times:
      set {_loc} to direction from player to {_midpoint}
      push player {_loc} at speed 0.5
      wait 2 ticks
and it is finding the center point accuratly :emoji_relieved:
 
Status
Not open for further replies.