Planetary rotations and revolutions in Unity


Work on Caelium is finally under way, but there will probably be only gradual progress. I implemented a system where celestial bodies can orbit around other celestial bodies and also a system where the bodies rotate on their axis.

To do this, two rotations were required: axial (around its axis) and orbital (around another body).  In Unity, when I tried to apply both types of rotations on a body (as a single GameObject), only the orbital rotation seemed to work.

To fix this problem, I had a simple GameObject hierarchy. You start with a CelestialAnchor, which is basically a point in space that orbits around another CelestialAnchor. It’s responsible for the position of the planet/star/moon and its orbital rotation.

Each CelestialAnchor holds a CelestialBody, which contains the 3D model of the planet/star/moon and does the axial rotation.

In this hierarchy, the planets have an orbital and axial rotation applied, as seen in the video. The speed of the rotations and the distances between the bodies can be tweaked in the editor.