This is a Unity project that simulates space gravity. It implements the following gravity equation:
Where F is the force due to gravity, between two masses (m1 and m2), which are a distance r apart and G is the gravitational constant.
The PlanetGravity script must be attached to an object the will exert gravity force. Then set property "Object to Attrach" with the object to apply the force.
An object can be put in orbit by setting the property Orbity to true:
In this case the following equation will be applyed to calculate the object velocity:
The direction of the object velocity always points along a tangent to its orbital path (blue line). And the planet gravity acts as a centripetal force (red line).
The magnitude of the velocity does not change due to gravity, but the direction constantly changes because the gravitational force constantly redirects it along a circular path. At any point in the orbit, the directions of the two quantities always point at a right angle, or 90 degress,to each other.