Skip to content

Instantly share code, notes, and snippets.

@Ribesg
Last active December 21, 2015 05:48
Show Gist options
  • Save Ribesg/6259106 to your computer and use it in GitHub Desktop.
Save Ribesg/6259106 to your computer and use it in GitHub Desktop.
// You may do this in PlayerMoveEvent or somewhere else.
// So you have those
final Player player;
final Location targetLocation;
// You get this one
final Location playerLocation = player.getLocation();
// You want the player to look at target
// First get the Vector that goes from the Player to the Target
final Vector direction = targetLocation.substract(playerLocation).toVector();
// Transform this direction Vector to a Pitch/Yaw couple
double pitch = ((player_location.getPitch() + 90) * Math.PI) / 180; // Magic
double yaw = ((player_location.getYaw() + 90) * Math.PI) / 180; // Magic too
// Create a location when the player will get teleported
// It will not move, just change the direction he's looking at
final Location teleportLocation = playerLocation.clone();
teleportLocation.setPitch(pitch);
teleportLocation.setYaw(yaw);
// And teleport the damn Player
player.teleport(teleportLocation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment