在围绕点的周期性圆形路径中移动对象

Moving an object in a periodical circular path around a point

我现在正在为一个game jam做一个游戏,问题是关于某个游戏敌人的飞行路径。我试图让它们中的几个编队飞行,我的想法是让它们在屏幕中心周围的一个宽半径圆圈内飞行,这样它们基本上就会包围玩家。为此,我尝试使用以下公式...

    public Pair<Double> move(Pair<Double> currPos, Pair<Double> playerPos) {
        Pair<Double> newPos = new Pair<>(currPos.x, currPos.y);

        // The radius used as the distance from the center.
        double r = (Framework.CANVAS_WIDTH / 2) - Player.SHIP_SIZE;
        // X,Y coords for center of the screen.
        double cX = (Framework.CANVAS_WIDTH / 2);
        double cY = (Framework.CANVAS_HEIGHT / 2);
        // Trigonometric equation for transforming the object in a circle.
        newPos.x = cX + (r * Math.cos(Framework.getHypotenuse(currPos, new Pair<Double>(cX, cY)) + (Math.PI / 90)));
        newPos.y = cY + (r * Math.sin(Framework.getHypotenuse(currPos, new Pair<Double>(cX, cY)) + (Math.PI / 90)));

        return newPos;
    }

我不明白为什么方程式似乎不起作用。当我测试移动模式时,屏幕上似乎有两个敌人围绕中心旋转,即使我只生成了一个。然而,它们眨眼的速度非常快,这让人觉得这艘船可能正在快速地来回跳跃。这是因为当我截图时,只有一艘船。是我的三角函数有什么问题导致了这个问题,还是问题出在其他地方?

以下伪代码给出了使对象沿圆形路径移动的标准方法:

double r  = (...);  // Radius of circle
double cX = (...);  // x-coordinate of center of rotation
double cY = (...);  // y-coordinate of center of rotation

double omega = (...);  // Angular velocity, like 1
double t = (...);  // Time step, like 0.00, 0.01, 0.02, 0.03, etc.

newPos.x = cX + r * Math.cos(t * omega);
newPos.y = cY + r * Math.sin(t * omega);