【发布时间】:2016-10-21 11:24:09
【问题描述】:
对于一个 Minecraft 项目,我想让玩家逐渐面对 (0, 60, 0)。到目前为止,当玩家在 (0, 60, 0) 周围移动超过 720° 时,我尝试的一切似乎都失败了。
有人知道如何让相机无缝移动到 (0, 60, 0) 吗?
谢谢!
这是我目前的代码(切换时循环运行):
int x = 0;
int y = 60;
int z = 0;
player = Minecraft.getMinecraft().thePlayer;
double dirx = player.posX - 0;
double diry = player.posY - 60;
double dirz = player.posZ - 0;
double len = Math.sqrt(dirx*dirx + diry*diry + dirz*dirz);
dirx /= len;
diry /= len;
dirz /= len;
double pitch = Math.asin(diry);
double yaw = Math.atan2(dirz, dirx);
//to degree
pitch = pitch * 180.0 / Math.PI;
yaw = yaw * 180.0 / Math.PI;
yaw += 90f;
if(yaw > player.rotationYaw) {
player.rotationYaw++;
} else if(yaw < player.rotationYaw) {
player.rotationYaw--;
}
没有 if 语句的这段代码可以正常工作。 yaw 和 pitch 变量以度为单位。
我遇到的问题是,每当我在 (0, 60, 0) 转几圈时,屏幕突然无缘无故地 360° 转动。
【问题讨论】:
-
你想从玩家当前看的任何方向旋转吗?您要查看的位置是世界上的某个位置还是相对于您的玩家?
player.rotationYaw是度数还是弧度? -
@ManIkWeet rotationYaw 以度为单位,我确定。
-
@ManIkWeet 以度为单位
-
@JustAJavaCoder 您是否尝试将
rotationYaw限制为-180180?我不明白您对the screen suddenly does a 360° turn, for no apparent reason.的意思,因为这不会明显改变您屏幕上的任何内容...