Orbital Mechanics Problem

I created a script which simulates sperical gravity; and I created an object which turns around the gravity source with some speed to avoid falling on gravity source. (Orbital Mechanics 101 :slight_smile: )

The script is supposed to increase gravity when object is closer to source and reduce when orbiting object goes far. This is how I ended up;

#pragma strict

public var target: Transform;
public var multiplicationFactor: float;
public var orbitalspeed: float;
var dist: float;
var plt: Transform;
var sun: Transform;

function Start () {
	GetComponent.<Rigidbody>().AddRelativeForce(Vector3.right * orbitalspeed);
}

function Update () {
	dist = Vector3.Distance(plt.position, sun.position);
}


function FixedUpdate () {
	GetComponent.<Rigidbody>().AddForce((target.position - transform.position) * multiplicationFactor / dist); 
}

MultiplicationFactor is my gravity constant, and dividing it by distance is supposed to increase gravity when object is closer to source object.

But unlike real life, I ended up with 2 periapsis and 2 apoapsis nodes. (Just google the terms). What am I missing, or doing wrong ?

Edit: Also the orbiting object’s orbit changes over time.
[64644-ekran-alıntısı.png|64644]

I also tried to use the distance squared, it ends up with the same result.

Oh, yes, my bad.

Normalizing the direction solved it.

[64651-ekran-alıntısı.png|64651]