I'm making a game in which the goal is to get as many planets as possible to orbit around a star. The user launches planets at any distance away from the sun (as long as it's on-screen), and in any direction (possibly even directly at the sun, though their game won't last very long).
This means orbits can be circular, elliptical, or--more than likely--irregular, something like this:
(Image originally from here)
The rules for my game that the player may launch planets as frequently as s/he likes...but they will only score a point for their first revolution (so spamming planets isn't likely to score very much).
Right now, the gravitational force is just F = ma
(i.e. a constant force towards the sun). I'm trying to figure out when a planet in arbitrary orbit has completed a full revolution. This is how I'm doing it currently...
// If this planet is active...
Vector2 a = _body.position.normalized;
Vector2 b = (a + _body.velocity).normalized;
float angle = Vector2.Angle (a, b);
this._total_angle += angle * Time.deltaTime;
if (this._total_angle >= 360) {
// If this planet has made a revolution...
++this._revolutions;
this._total_angle = 0;
this.OnRevolution.Invoke (this);
}
However, this is incorrect for anything besides circular orbits. No good.
Given all of this (and my near-total unfamiliarity with orbital mechanics), how can I tell when a planet in an arbitrary orbit has completed one full revolution?
EDIT: No, the planets will not affect each other's orbits (though they can collide into one another, but they'll just explode).