簡體   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