简体   繁体   English

围绕中心点旋转物体

[英]Rotate bodies around around a center point

I have a game world in which the player rotates around a point (like a planet). 我有一个游戏世界,玩家在其中旋转某个点(例如行星)。 How can I rotate a body around a center point? 如何围绕中心点旋转身体? I also want to somehow be able to use something like the actor classes interpolation for moving things, is that possible? 我还想以某种方式能够使用诸如actor类插值之类的东西来移动物体,这可能吗? Thanks! 谢谢!

You can rotate via vector2 easly. 您可以通过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

You can also use actor methods. 您也可以使用actor方法。

Just define new variable like is_in_orbit and if its true (in orbit) then rotate otherwise move with a actor classes interpolation methods. 只需定义新变量,例如is_in_orbit ,然后将其定义为true(在轨),然后旋转即可,否则使用actor类插值方法进行移动。

By the way you also have a opinion to use physics since Newton's law of universal gravitation is also physics but it will be complicated and can cause unexpected results in case of more center points (planets as you said) appear. 顺便说一句,由于牛顿的万有引力定律也是物理学,所以您也有使用物理学的意见,但是如果出现更多的中心点(如您所说的行星),它将很复杂并且会导致意外的结果。

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

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