I'm creating a game with planets orbiting around a sun, like this:Earth orbiting sun

The brown square is the earth, rotating around its center and around the sun. The yellow square is the sun, which doesn't move.

Now imagine a player standing on the planet, the planet moves at a velocity of 20 m/s. How do I prevent the player from falling off? I have to give the perception to the player that the planet isn't moving.

I got the gravity on earth working, but I don't know how I can keep the player on the planet! I have thought about two solutions until now:

  1. Just apply the angular velocity and linear velocity of the planet on the player (if it's in a specified radius), I think this method will cause jittery movement/glitches.

  2. Create a separate Box2D world for the planet and render this Box2D world with the rotation/translation of the planet. This method is complex though since it would add the problem of moving bodies between different worlds if the player would leave the planet. This image explains it:

    enter image description here

I think there is another (better) way to fix this problem, but I haven't found a solution yet.

  • \$\begingroup\$ What does 'falling off' look like? Does the player fall into the sun? Do they get pulled towards earth when it is near and just bounce off? Also, is the planet rotating about it's own axis while moving around the sun? \$\endgroup\$ Jan 28 '15 at 21:51
  • \$\begingroup\$ Also, why are you talking about rendering at the end? (-1) This question should be focused on physics or rendering, not both. \$\endgroup\$ Jan 28 '15 at 21:53
  • \$\begingroup\$ Imagine you're standing on a platform. When the platform moves you fall off it because there is not enough friction. This happens now too on the planet, so I want to have the player stay on the planet instead of falling off when the planet moves. Please read the post regarding the question about axis-movement, I clearly state it there. About the 'rendering' at the end. That solution is hardly about the rendering. It is about giving each planet their own relative world. Please read the whole post before answering. \$\endgroup\$
    – Ives
    Jan 29 '15 at 9:34
  • \$\begingroup\$ I understand now. Thanks for the clarification. I can't (rules of stack exchange) remove the downvote until you make another edit. A useful edit would be to add the sentence about not enough friction into your question. An even better edit would be to include a gif or link to a short vid of your game that shows the player 'falling off' the planet. \$\endgroup\$ Jan 29 '15 at 13:53
  • \$\begingroup\$ Ah no problem! The second solution I gave seems to have worked! imgur.com/rPM3OgV \$\endgroup\$
    – Ives
    Feb 1 '15 at 16:47

It works now! I have created a seperate Box2D world for every planet and Solar Systems. The Solar System rotates the planet, so it looks like the planet is rotating. But the player (in the world) isn't rotating at all.

The result looks like this: http://imgur.com/rPM3OgV


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.