2016-08-17 136 views
0

我有一个游戏世界,玩家围绕一个点(如行星)旋转。我怎样才能围绕中心点旋转身体?我也想以某种方式能够使用类似动画类插值的东西来移动东西,这有可能吗?谢谢!围绕中心点旋转身体

回答

2

您可以通过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类插值方法移动。

顺便说一句,你也有一个意见来使用物理学,因为牛顿的万有引力定律也是物理的,但它会变得复杂,并且会在出现更多中心点(行星如你所说)的情况下导致意想不到的结果。

+0

我知道我可以使用演员类,但我也想使用box2d作为碰撞。我仍然对某些事情感到困惑,我怎样才能真正旋转身体?我看到你正在使用矢量来获得一个角度,我如何设置身体到那个角度? – Wyatt

+0

其实我有这个位置。 vectorbody.x和vectorbody.y是body的新坐标。你可以用bodyDef.position.set(vectorbody.x,vectorbody.y)设置body的位置; –

+0

我猜想你错过了。我说的是身体围绕中心旋转而不是身体旋转时的位置。你可以研究一下body.setTransform(body.getPosition(),angle); –