# Relative movement in Box2D (keep object from falling off planet)

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

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:

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

• 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? Jan 28, 2015 at 21:51
• Also, why are you talking about rendering at the end? (-1) This question should be focused on physics or rendering, not both. Jan 28, 2015 at 21:53
• 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.
– Ives
Jan 29, 2015 at 9:34
• 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. Jan 29, 2015 at 13:53
• Ah no problem! The second solution I gave seems to have worked! imgur.com/rPM3OgV
– Ives
Feb 1, 2015 at 16:47