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:
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.
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.