planet gravity

Hi all!
Does anyone worked with “planet” gravitation and can show how it could be implemented?
What i’m doing: trying to write small simulator of our sun system with asteroids and satellites. It’s actually not too many well documented or easy to understand examples, or http://en.wikipedia.org/wiki/Three-body_problem
Thanks for advance! (and sorry for my English)

the only thing coming on my mind is to recalculate gravity vector on some time period (maybe each frame)
and apply new vector to objects

I don’t think that I’ve ever built a three-body system, but calculating and applying the appropriate forces is probably what I’d try first.

I will note, however, that you may want to look into implementing a fixed timestep: it may prove more stable than using a variable timestep.

Thanks for answer
will soon see results :slight_smile:

What is the gameplay you are trying to go for?

as I said, Its about living on planets. Main idea is to make something like spaceengine in distant graphics,like rpg+strategy game on surface.
(I’m always lot of ideas, but I have only 1 life to made em all)

The three body problem is very expensive to calculate and you probably don’t need it. There are faster alternatives.

Planet motion: Put these on rails. Just use circular orbits. If for some reason you need realistic planetary motion you can use a library I wrote that calculates the position of a body, relative to its parent body, based on the six kepler orbital parameters and time.

Unit motion: You can do a two body problem. Precalculate the sphere of influence
for each body. Then periodically check which soi a unit is in. Then calculate gravity with the correct parent body. If you are looking for an even faster method check out patched conics.

yes, Its difficult, and now I’m implementing simplified model, but experiments shows that small cheating with formulas and methods could also bring nice result without decreasing speed. If they will be successful, I’ll share with you :slight_smile: