我想让一个物体围绕另一个物体旋转。我觉得这不太难。但结果是一个螺旋形的圆圈... 我可能使用了错误的公式,但我不确定应该用哪个公式代替...
var dx = this.x - this.parent.x,
dy = this.y - this.parent.y,
r = Math.atan2(dy, dx);
this.x = Math.sin(r) * this.speed + this.x;
this.y = (Math.cos(r) * this.speed * -1) + this.y;
当您执行此代码时,它似乎可以工作。每个帧,对象将在其父对象周围的弧线上移动。
然而,这条弧线变得越来越大,距离也越来越远。
我犯了什么错误?