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:

  1. An Orbiting Object struct,
  2. 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.

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Leetcode 160. Intersection of Two Linked Lists

OpenStack — An Open Source Cloud Computing Platform

Climbing the API mountain of electric vehicle charging

Why need to be careful when mounting single files into a Docker container

How to Build Java Applications Today: #52

Getting Started with Sass

KogeFarm 2.0: The Unveiling

How Programming in the Small Can Make You A Big Shot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

Creating an emission map texture

Making A 3D Backdrop Using ProBuilder In Unity

Using Decals in Unity

Unity TileMap: Smooth Movement in a Top-Down Game