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

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

1. ### nokoa

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. ### Ciaaran

Edit it in the config/where the spawn points save.

• Useful x 1
4. ### Kloudy

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 x 1

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 x 2
6. ### Xilixir

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.

well now I know that setting a player's new location is not a method

my bad you didn't understand carefully, expected that all values to get would be in config.

• Optimistic x 1
8. ### Xilixir

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.