# Why doesn't my orbit form an ellipse?

I'm playing around and trying to build an orbit simulator. Unfortunately, it isn't working out to well. Instead of forming some sort of elliptical orbit, I get this: Here is the code I'm using to generate the orbits:

public class OrbitBehaviour : MonoBehaviour {
public Double Mass;
private List<GameObject> _bodies = new List<GameObject>();
private float _gravConstant = 6.673f * Mathf.Pow(10.0f, -11.0f); // Units: m3 kg-1 s-2
private int delay = 0;
private float _distanceConversion = 6.68458712f * Mathf.Pow(10.0f, -12.0f); // m -> AU (Astronomical Units)
private float _massConversion = 1.67403241f * Mathf.Pow(10.0f, -25.0f); // kg -> E (Earth masses)
private float _timeConversion = 1.1574074074074074074074074074074e-5f; // s -> D (Days)

// Use this for initialization
void Start() {
_bodies = GameObject.FindGameObjectsWithTag("mass").ToList();
_gravConstant *= Mathf.Pow(_distanceConversion, 3.0f);
_gravConstant /= _massConversion;
_gravConstant /= Mathf.Pow(_timeConversion, 2.0f);
Mass = Mass * _massConversion;
Time.timeScale = 99.0f;
}

// Update is called once per frame
void FixedUpdate() { StepSimulation(); }

private void StepSimulation() {
// Walk each body in the system
foreach (GameObject body in _bodies) {
if (gameObject == body) {
continue; //skip self
}
Vector3 tSeparationVector = body.transform.position - gameObject.transform.position;
tSeparationVector = tSeparationVector.normalized;
OrbitBehaviour bodyBehaviour = body.GetComponent<OrbitBehaviour>();
Double tForceValue = _gravConstant * (this.Mass * bodyBehaviour.Mass / tSeparationVector.sqrMagnitude);

• Change all your floats to doubles. That will reduce the magnitude of the behaviour significantly, but the true origin is that you are assuming perfect integration of finite-precision numbers, and the rounding errors are accumulating. – Pieter Geerkens Jul 16 '15 at 2:12
• @v.oddou Unity's integrator is not extensible. It gives you only an interpolation property that'll take None, Interpolate, or Extrapolate. My guess is that they're all euler, but I can't find anything in the Unity API confirming that, nor anything in the PhysX SDK with the same naming. Unity API here: docs.unity3d.com/ScriptReference/Rigidbody-interpolation.html – Slipp D. Thompson Dec 15 '15 at 21:50