繁体   English   中英

围绕中心点旋转物体

[英]Rotate bodies around around a center point

我有一个游戏世界,玩家在其中旋转某个点(例如行星)。 如何围绕中心点旋转身体? 我还想以某种方式能够使用诸如actor类插值之类的东西来移动物体,这可能吗? 谢谢!

您可以通过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 ,然后将其定义为true(在轨),然后旋转即可,否则使用actor类插值方法进行移动。

顺便说一句,由于牛顿的万有引力定律也是物理学,所以您也有使用物理学的意见,但是如果出现更多的中心点(如您所说的行星),它将很复杂并且会导致意外的结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM