围绕中心点旋转身体
答
您可以通过vector2轻松旋转。
Vector2 vectorbody = new Vector2(50f, 50f);
Vector2 vectorcenter = new Vector2(100f,100f);
Vector2 vectordis= vectorbody.cpy().sub(vectorcenter);//Displacement vector center to body
vectordis.setAngle(vectordis.angle() + rotatespeed);//Rotate speed can be negative that means it will rotates to other side.
vectordis.add(vectorcenter); //vectordis now became rotated vectorbody
vectorbody.set(vectordis); //vectorbody updated
您也可以使用actor方法。
只需定义像is_in_orbit这样的新变量,并且如果它的真实(在轨道)然后旋转,否则用一个actor类插值方法移动。
顺便说一句,你也有一个意见来使用物理学,因为牛顿的万有引力定律也是物理的,但它会变得复杂,并且会在出现更多中心点(行星如你所说)的情况下导致意想不到的结果。
我知道我可以使用演员类,但我也想使用box2d作为碰撞。我仍然对某些事情感到困惑,我怎样才能真正旋转身体?我看到你正在使用矢量来获得一个角度,我如何设置身体到那个角度? – Wyatt
其实我有这个位置。 vectorbody.x和vectorbody.y是body的新坐标。你可以用bodyDef.position.set(vectorbody.x,vectorbody.y)设置body的位置; –
我猜想你错过了。我说的是身体围绕中心旋转而不是身体旋转时的位置。你可以研究一下body.setTransform(body.getPosition(),angle); –