Gravity is a very weak force. Unless you’re doing a space simulation game (or a something else involving custom physics), you won’t need the actual formula for gravity. For most games you can just use their built-in physics system (i.e. Using the RigidBody or RigidBody2D component in unity)

Although TECHNICALLY gravity does fluctuate based on your change in mass and distance from the center. Those changes are so insignificant though. Even between the lowest and highest places on earth, the change is very insignificant.
- Mount Everest – g≈9.773 m/s2
- Sea Level – g≈9.80665 m/s2
- Mariana Trench (not including all the water) – g≈9.8100 m/s2
The gravitational formula is actually very simple and easy to implement in code.

In code, that looks like this
public Vector3 GetGravityForce(Vector3 object1Position, Vector3 object2Position, float m1, float m2)
{
Vector3 difference = (object2Position - object1Position);
float rSquared = difference.magnitude * difference.magnitude;
Vector3 force = GameConstants.GravitationalConstant * difference.normalized * m1 * m2 / rSquared;
return force;
}
The gravitational constant in real life is incredibly tiny. In my game Gravitational Cores, i used a much larger value to adjust the play experience:
- Real Life: G=0.0000000000667430000 m3kg−1s−2
- My version: 100
Most people won’t need to use this, but it’s cool knowledge to know. I hope you found this helpful.