I'm making a 2D game where you control a spaceship and fly between disk-formed planets of differing size (mass/pull). The planets are small and you can fly near several at once. I need to calculate the gravity produced by each of these planets pulling on the ship including the velocity of the ship.
I figured out a way to approximate it:
- Calculate the position of the rocket in the next frame based on the angle and velocity
- From this position, calculate the position of a point pulled towards the planet where the larger the planet, the further this point is towards said planet
- Do this for each planet then average each of these points to find the new location for the rocket this frame
- Rotation doesn't matter in my case, but I would calculate it by comparing this point's location and the previous point's location.
- Repeat for every frame.
This may be a good approximation, and accuracy isn't a huge deal in my case, but I am wondering if there is a better way to do this with physics formulas. I haven't taken a physics class yet. The other main problem with this solution is that it must calculate it step by step or frame by frame. If there is a formula to do this the path could be calculated from the very start before.