Well, I was looking for input on how to do this, and everyone just said that I should use local coordinates + a baseline. Why make it more difficult than that?
Ok so i am bumping a sleepy thread… But i spent some time on this in the weekend and decided to write it down for posterity.
Long story short, simulation of the larger bodies (planets, moons and stars) is a waste of time. Getting it to work well enough that planets don’t get randomly ejected to plunged into the sun is hard for long term and tedious but more to the point, a total waste of time. Consider that parametric equations of motion would actually be more accurate that a PhD thesis of simulation code. It is why we use it for 99.9% of real multiyear mission probe navigation and star finders etc. It is just that good.
Now for a game you don’t need the full accuracy and if you are only going for 2d you can’t get the accuracy anyway (2nd order effects include orbital plane drift). So either have just planets with circular orbits (dead easy) or got the proper ellipse equation of motion, which is not much harder. Doing the calculations are just some multiplies and a few sqrts to look up the state of anything at any time. You still need to use a local coordinate system centered on whatever the thing is orbiting. But errors don’t accumulate, so round off errors don’t really matter.
For space craft etc, using a integrator is what i would do… BUT this means some fairly complicated controller so that it can get to where you want it to go. Again this is accurate since it only cares about where the large things are which is also accurate and stable due to parametric equations of motion. Large time steps could still work well and bobs your uncle it is all easy. Once a ship is in orbit, it is easy to calculate a new orbit with a “burn”.
So at large scale you have stars. And shot scale you have planet systems. Since the scale factor between these is more than 100, they are effectively independent.
Oh and the other day, i did a chart of all the 1000 closest stars and made it into a 2d map where it tried to preserve the distance between all the stars to be the same as in the 3d case. Interesting. There is a lot of stars out there.
Yeah, I´ll use equations for the planets´/ moons´ orbits.
The AI of the game is probably the biggest problem I´ve found in this kind of simulation. How do I calculate a “burn” which gets the ship from one orbit to another?
There almost never is 1 burn that will do the job. It’s annoying that the target is always moving. You can probably only simulate it, and converge to a solution.
Better yet: fake it, just like with the orbits of the planets. Calculate the rough trajectory and then pull the spacecraft in the orbit.
Its a bit of both. It is a Hohmann transfer orbit for the most part. This is easy to calculate. This give a transfer with the least amount of propellant with the assumption that you very short burns.
Anything else is done just as Riven has said.
Cool example: The pioneer anomaly was caused by one side of the space craft being slightly hotter than the other. The photon pressure has pushed slightly more off course than was expected. Again too accurate for your case.