How to set yaw and pitch to look at a location?

Discussion in 'Spigot Plugin Development' started by nokoa, May 27, 2016.

  1. Hello, I am looking to create minigame spawn points and I want all players to automatically look at a middle point which I set. So when players spawn in different locations they will all look at the direction to the middle point.

    How can I do that?
     
  2. Edit it in the config/where the spawn points save.
     
    • Useful Useful x 1
  3. You could try something like:

    Code (Text):

    //middlePt would be the Location object of your middle location
    double x = middlePt.getX() - player.getLocation().getX();
    double y = middlePt.getY() - player.getLocation().getY();
    double z = middlePt.getZ() - player.getLocation().getZ();

    Vector playerLookDirection = new Vector(x, y, z);//make a vector going from the player's location to the center point

    player.getLocation().setDirection(playerLookDirection.normalize());
     
    • Informative Informative x 1
  4. Code (Java):
    World w = // get world
    double x = // get x
    double y = // get y
    double z = // get z
    double yaw = // get yaw
    double pitch = // get pitch

    Player#setLocation(new Location(w, x, y, z, (float) yaw, (float) pitch));
     
    • Funny Funny x 2
  5. First, he's trying to calculate the yaw/pitch needed for the player to be looking at the location without knowing the yaw/pitch before hand.

    Second, that's not a method.
     
  6. well now I know that setting a player's new location is not a method :p

    my bad you didn't understand carefully, expected that all values to get would be in config.
     
    • Optimistic Optimistic x 1
  7. No you're the one who didn't understand. He's trying to make a list of players look at the same location, so he needs to calculate each one individually in the code.
     
  8. lool yeaaaaah boy Wrong thread I thought it was the bukkit ones whom I was talking to.

    he's asking for set location then go with yaw and pitch.

    its really shameful :p hahaha didn't read what @OP's talking about.