Skip to content

Instantly share code, notes, and snippets.

@Sposito
Last active October 10, 2018 17:06
Show Gist options
  • Save Sposito/9faa94fd161c44c19a35a5b4953657f5 to your computer and use it in GitHub Desktop.
Save Sposito/9faa94fd161c44c19a35a5b4953657f5 to your computer and use it in GitHub Desktop.
public void Step()
{
float dx2 = position.x - orbitParent.position.x;
dx2 *= dx2;
var time = Time.deltaTime;
float dy2 = position.y - orbitParent.position.y;
dy2 *= dy2;
var r2 = dx2 + dy2;
var scalarForce = konstG * (mass + orbitParent.mass) / r2;
var scalarAcc = scalarForce / mass;
var acc = (position - orbitParent.position).normalized * scalarAcc;
speed = (acc * time) + speed;
position += speed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment