Can't set player's yaw and pitch

Discussion in 'Plugin Development' started by redside100, Jan 23, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    redside100

    Hey, I have a problem. I want to make it so when a player teleports, the player's direction also changes. I know that yaw and pitch are both floats, but for some reason it won't work when I try to set their direction. Here's my code:

    I run this everytime a new position is set:
    Code:
        public void refreshLocations(){
            yaw1 = Float.parseFloat(getConfig().getString("arena.lobby.yaw"));
            yaw2 = Float.parseFloat(getConfig().getString("arena.spawnpoint1.yaw"));
            yaw3 = Float.parseFloat(getConfig().getString("arena.spawnpoint2.yaw"));
            pitch1 = Float.parseFloat(getConfig().getString("arena.lobby.pitch"));
            pitch2 = Float.parseFloat(getConfig().getString("arena.spawnpoint1.pitch"));
            pitch3 = Float.parseFloat(getConfig().getString("arena.spawnpoint2.pitch"));
            loc1 = new Location(Bukkit.getWorld(getConfig().getString("arena.spawnpoint1.world")),
                    getConfig().getDouble("arena.spawnpoint1.x"), getConfig().getDouble("arena.spawnpoint1.y"),
                    getConfig().getDouble("arena.spawnpoint1.z"), yaw1, pitch1);
            loc2 = new Location(Bukkit.getWorld(getConfig().getString("arena.spawnpoint2.world")),
                    getConfig().getDouble("arena.spawnpoint2.x"), getConfig().getDouble("arena.spawnpoint2.y"),
                    getConfig().getDouble("arena.spawnpoint2.z"), yaw2, pitch2);
            loc3 = new Location(Bukkit.getWorld(getConfig().getString("arena.lobby.world")),
                    getConfig().getDouble("arena.lobby.x"), getConfig().getDouble("arena.lobby.y"),
                    getConfig().getDouble("arena.lobby.z"), yaw3, pitch3);
        }
    And then I teleport a player to the position.
     
  2. Offline

    PreFiXAUT

    Simply get it as a double (you might need to parse it with "(float)"). Normaly the Player#teleport() Method already takes care about the yaw and pitch.

    Did you try to debug it?
     
  3. Offline

    redside100

    I've already tried getting it as a double, but it didn't work. I debugged it, by adding getServer().broadcastMessage("" + yaw1), and it broadcasted a number like -150.231982309123 or something. @PreFiXAUT
     
    Last edited: Jan 23, 2015
  4. Offline

    PreFiXAUT

    @redside100 Negative yaw? Ok...guess we found the problem. The yaw is ranged from 0-360, and it's probably gonna mess up with a negative one. So try to use positive yaws in the range of 0-360 and then everything should work out fine :)
     
  5. Offline

    redside100

    Well, I tried another location that gave a positive yaw, but it still didn't work ;-;
     
Thread Status:
Not open for further replies.

Share This Page