【发布时间】:2012-07-17 00:59:18
【问题描述】:
所以我无法让我的砂矿面对一颗行星。我有玩家和星球之间的角度,我也有玩家当前所处的角度,现在我想要做的是让我的玩家面对星球,但有增量变化。 (我这样做是因为我希望我的砂矿能够绕地球运行)
问题出在数学上,我增加了玩家旋转以匹配玩家和行星之间的角度,但是因为角度在 0 到 360 范围内工作,所以我的玩家不会绕轨道运行,因为玩家旋转可能是 2 但是与行星的角度是280所以游戏会让玩家转身,抱歉解释不好。
有谁知道如何让我的玩家成功环绕我的星球运行?
这是我的代码:
double rotation = Math.toDegrees(Math.atan2(currentPlanet.pos[1]-currentPlayer.pos[1], currentPlanet.pos[0]-currentPlayer.pos[0]));
if(rotation < 0)
{
rotation += 360;
}
if(currentPlayer.rotation < rotation)
{
currentPlayer.rotation += 0.15*delta;
}
if(currentPlayer.rotation > rotation)
{
currentPlayer.rotation -= 0.15*delta;
}
【问题讨论】: