Skip to content

Instantly share code, notes, and snippets.

View ovbm's full-sized avatar
😷

Olivier Baumann ovbm

😷
View GitHub Profile
@ovbm
ovbm / orbital_gravity_2d.cs
Created July 31, 2017 22:41 — forked from oliverholmberg/orbital_gravity_2d.cs
Orbital Gravity 2D - A demonstration of Orbital Gravity in a 2D Unity Game. Unity's standard physics engine implements gravity only in the vertical axis. Here's a demo of orbital gravity for space type games. It allows for one object (spaceship, satellite, etc.) to achieve a stable organic orbit around another object (planet, moon, star, etc.)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
// Intended to be attached to a GameObject in order for that object to have its own gravity.
// Standard Unity Gravity is disabled on objects implementing this class
// This class is pared down from the original WorldBodyController used Oliver Holmberg's game Apogee to simply demonstrate orbital gravity.
public class OrbitalGravityObject : MonoBehaviour {