Hello everyone

I have been working on a project which will accurately simulate the gravitational interactions between bodies using Newton’s law of universal gravitation. To make sure it is working, I have created an approximation of the Earth-Moon system to see if the orbital period of the moon is the same as it is in real life. The problem is that the moon goes way too fast but in more or less the correct orbit. It’s as if the time scale was a lot faster. Instead of having an orbital period of 27 days (2332800 s) it goes over 800 times faster. The actual timescale is set to 1, so if all my math is right, it should be moving almost exactly the same as the moon.

To make the scale and distances easier to handle I have made all the distances 100000 times smaller (the distance between the Earth and Moon is 3844 m instead of 384400000 m), and to make up for this change I have made the gravitational constant ten times smaller because the distance is squared, so 100000^2 = 10^10. You can see all of this in the code below. And as for the masses of each object, I have made a separate variable inside the script attached to each object which can handle the enormous masses of the earth and moon, and have left the rigidbody mass of each attractor as 1 and have left the body to attract’s mass out of the equation. I’m sorry if this is really confusing.

I don’t know if the problem is with my math or with the way I’m applying forces or something else. Thank you for any help

```
public class Attractor : MonoBehaviour {
public Rigidbody rb;
public Vector3 startVelocity;
const double G = 0.000000000000000000006674; // Gravitational constant adapted proportionally to distances and scale (normal value = 6.674*10^-11 = 0.0000000000674)
public static List<Attractor> Attractors;
public double mass;
void FixedUpdate () {
foreach (Attractor attractor in Attractors) {
if (attractor != this) {
Attract (attractor);
}
}
}
void OnEnable () {
rb = GetComponent<Rigidbody>();
rb.velocity = startVelocity;
if (Attractors == null) {
Attractors = new List<Attractor> ();
}
Attractors.Add (this);
}
void OnDisable () {
Attractors.Remove (this);
}
void Attract(Attractor bodyToAttract) {
Rigidbody rbToAttract = bodyToAttract.rb;
Vector3 direction = rb.position - rbToAttract.position;
float distance = direction.magnitude;
Debug.Log(distance);
if (distance == 0)
return;
double forceMagnitude = G * mass / Mathf.Pow (distance, 2); // I don't need to multiply by mass on top because when you use rb.AddForce it uses the mass of the rb which is 1, If I did add the actual mass variable of the other body it would add a force way too large
Vector3 force = direction.normalized * (float)forceMagnitude;
rbToAttract.AddForce (force, ForceMode.Force);
}
}
```