如何将玩家传送到他左边两个街区?

How to teleport a player two block on his left?

我尝试了几种方法,比如使用矢量,但对我来说不起作用。比起我尝试在互联网上搜索,它也没有用。

Vector direc = l.getDirection().normalize();
direc.setY(l.getY());
direc.normalize();
direc.multiply(-1);
l.add(direc);

Player#teleport(l.getBlock().getLocation());
// or
Player#teleport(l);
Location location = player.getLocation();
Vector direction = location.getDirection();
direction.normalize();

float newZ = (float)(location.getZ() + (2 *  Math.sin(Math.toRadians(location.getYaw() + 90 * direction)))); //2 is your block amount in Z direction
 
float newX = (float)(location.getX() + (Math.cos(Math.toRadians(location.getYaw() + 90 * direction))));

您必须知道要将玩家传送到哪个方向

使用Vector#rotateAroundY 将玩家的方向向量向左旋转90度。

Vector dir = player.getLocation().getDirection();     // get player's direction vector
dir.setY(0).normalize();                              // get rid of the y component
dir.rotateAroundY(Math.PI / 2);                       // rotate it 90 degrees to the left
dir.multiply(2);                                      // make the vector's length 2
Location newLocation = player.getLocation().add(dir); // add the vector to the player's location to get the new location