Solved How to set Pitch and Yaw in 1.9?

Discussion in 'Plugin Development' started by TheSporech, Apr 8, 2016.

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

    TheSporech

    Hi, just what the title says. I can't seem to do player.get/setPitch() or player.get/setYaw() anymore. Is there a new way to do this?

    Edit: I know you can enter them as arguments when you create a new location, but is there a better way of doing this?
     
  2. Offline

    Orange Tabby

    Have you tried:
    Code:
    player.getLocation().getYaw();
    player.getLocation().getPitch();
    
     
  3. Offline

    TheSporech

    Yes, I did find it, but it doesn't seem to be working.

    Here's the code with it in to give you some context:
    Code:
    float pitch = e.getLocation().getPitch();
                            float yaw = e.getLocation().getYaw();
                            switch(colour) {
                            case blue:
                                v = switchvelocity(e.getVelocity(), gun.yp,gun.bp);
                                switch (gun.yp.surface) {
                                case UP:
                                    pitch = -90;
                                    break;
                                case DOWN:
                                    pitch = 90;
                                    break;
                                case NORTH:
                                    yaw = -180;
                                    break;
                                case SOUTH:
                                    yaw = 0;
                                    break;
                                case EAST:
                                    yaw = -90;
                                    break;
                                case WEST:
                                    yaw = 90;
                                    break;
                                default:
                                    break;
                                }
                                e.teleport(gun.yp.getLocation().clone().add(gun.yp.offset));
                                e.getLocation().setPitch(pitch);
                                e.getLocation().setYaw(yaw);
                                break;
                            case yellow:
                                v = switchvelocity(e.getVelocity(), gun.bp,gun.yp);
                                switch (gun.bp.surface) {
                                case UP:
                                    pitch = -90;
                                    break;
                                case DOWN:
                                    pitch = 90;
                                    break;
                                case NORTH:
                                    yaw = -180;
                                    break;
                                case SOUTH:
                                    yaw = 0;
                                    break;
                                case EAST:
                                    yaw = -90;
                                    break;
                                case WEST:
                                    yaw = 90;
                                    break;
                                default:
                                    break;
                                }
                                e.teleport(gun.bp.getLocation().clone().add(gun.bp.offset));
                                e.getLocation().setPitch(pitch);
                                e.getLocation().setYaw(yaw);
     
  4. Offline

    MisterErwin

    @TheSporech Try to teleport the player AFTER you have set the yaw and pitch of the destination location
     
  5. Offline

    Zombie_Striker

    @TheSporech @MisterErwin
    You have to teleport the player to a Location, where the location contains the yaw and the pitch for the player.
    Code:
    loc.setYaw(yaw);
    loc.setPitch(pitch);
    Player#teleport(Loc );
     
    MisterErwin likes this.
  6. Offline

    TheSporech

    Thanks this solved it!
     
Thread Status:
Not open for further replies.

Share This Page