From b800bdad29af167627834bf444b674d4276292da Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 May 2020 23:16:26 +0200 Subject: [PATCH] Add Pitch/Yaw calculation with Vector --- .../src/de/steamwar/fightsystem/Config.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 78e91a8..13a2da8 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -9,6 +9,7 @@ import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.util.Vector; import java.io.File; import java.util.*; @@ -250,10 +251,10 @@ public class Config { TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ; World world = Bukkit.getWorlds().get(0); - double yaw = Math.toDegrees(Math.atan2(TeamBluetoReddistanceZ, TeamBluetoReddistanceX) + Math.PI / 2); - double pitch = Math.toDegrees(Math.atan2(Math.sqrt(TeamBluetoReddistanceZ * TeamBluetoReddistanceZ + TeamBluetoReddistanceX * TeamBluetoReddistanceX), TeamBluetoReddistanceY)); - double yawInverted = ((yaw + 180) * 180) / 180; - double pitchInverted = ((90 - pitch) * 180) / 180; + //double yaw = Math.toDegrees(Math.atan2(TeamBluetoReddistanceZ, TeamBluetoReddistanceX) + Math.PI / 2); + //double pitch = Math.toDegrees(Math.atan2(Math.sqrt(TeamBluetoReddistanceZ * TeamBluetoReddistanceZ + TeamBluetoReddistanceX * TeamBluetoReddistanceX), TeamBluetoReddistanceY)); + //double yawInverted = yaw + 180; + //double pitchInverted = ((90 - pitch) * 180) / 180; TeamBlueSpawn = new Location(world, TeamBluePasteX + 0.5 + teamBlueSpawnOffsetX, @@ -265,11 +266,17 @@ public class Config { TeamRedCornerY + 0.5 + teamBlueSpawnOffsetY, TeamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); - TeamBlueSpawn.setYaw((float)yawInverted); - TeamBlueSpawn.setPitch((float)pitchInverted); + Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector()); + double pitch = v1.angle(v1.clone().setY(0)); + double yaw = v1.clone().setY(0).angle(new Vector(1, 0, 0)); + double pitchInverted = pitch * -1; + double yawInverted = yaw + 180; - TeamRedSpawn.setYaw((float)yaw); - TeamRedSpawn.setPitch((float)pitch); + TeamBlueSpawn.setYaw((float) yawInverted); + TeamBlueSpawn.setPitch((float) pitchInverted); + + TeamRedSpawn.setYaw((float) yaw); + TeamRedSpawn.setPitch((float) pitch); SpecSpawn = new Location(world, TeamBluePasteX + TeamBluetoReddistanceX/2.0,