My ducks don't need batteries

Newton was almost right

N

In this day and age it is clear that Newtonian physics works well at a small scale but not perfectly when trying to calculate trajectories of planets and such. Nonetheless, it is still a good enough aproximation for a game and as such that’s what I’ll be using for this next phase.

Essentially, what I’ll talk about today amounts to creating a solar system replica in C#. For this we only really need to know a few equations:

\Large F = G * \frac {m_1 * m_2} {d^2}

The equation above is what we’ll use to calculate what force needs to be applied to each celestial body. Besides it we will need a second one that will help us calculate the mass (m) of the body based on its radius (r) and gravitational acceleration at its surface (g). This second one comes from the equation used to calculate (g) rearranged to solve for (m) instead.

\Large
g = \frac {G * m} {r^2} \Rightarrow m = \frac {g * r^2} {G}

Now, you might wonder just what is this “G” that keeps popping up. As it’s lower case brethren (g) it is still related to gravity. The “G” refers to the gravitational constant, the value of which is below, expressed in its SI unit.

\large
G = 6.67430(15) * 10^{-11} m^3 * kg^{-1} * s^{-2}

Finally, we must keep in mind that we’re mostly going to work with velocities and positions instead of relying on Unity’s built in rigid bodies for physics. As such, working with forces is all well and good for calculations but at the end of the day we need to get a velocity to be added to the position out of the force. For that we’ll use the equation below:

\Large 
\begin{aligned}
F = m * a \rightarrow a = \frac F m
\\
V = a * \Delta T
\end{aligned}
\space\space\space \Bigg \vert \rightarrow
V = \frac F m * \Delta T

That’s it for the physics at this point. Later on, once we’ll have spacehips moving around, these formulas will come back to aid in some maths there but for now it’s time to move on to creating the solar system. I’d like the game to have a lot of these solar systems running in parallel and to keep them as encapsulated as possible. Moreover, floats might not cut it. These numbers are worthy of a blog post on their own but let’s keep on topic for now. If you want that information now, here’s a great post going over floating point numbers in detail.

My ducks don't need batteries