Coding A Planet Orbit
As a small side-project recently, I made a planet orbit system for having objects orbit around a central object in an Ellipse shape.

Today’s Objective: Make a planetary-orbit system using the previously-created Ellipse generator (Part 1 & Part 2).
The Code:
The design I’ve settled on for the orbit system is made up of 2 elements:
- An Orbiting Object struct,
- And a Orbit Ring component.
The Orbiting Object:
This will represent the object which will orbit around the Orbit Ring, and it’s data. Very simple.

The Orbit Ring:
Firstly I need some variables to create and manage the orbit ring. These are put in a MonoBehaviour class called “OrbitRing”.

Next for the functionality of the rings.
On start of scene:

Update every frame:

Update when values change:

Display the ring:

Finally, you can also show the ellipse in the Scene view without needing a Line Renderer by creating an OnDrawGizmos( ) method. It uses the already-created-and-stored ellipse path to draw many lines and show the ellipse.

