简体   繁体   中英

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? Thanks!

You can rotate via vector2 easly.

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.

Just define new variable like is_in_orbit and if its true (in orbit) then rotate otherwise move with a actor classes interpolation methods.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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