Physics has always fascinated me. Even though I'm not the brightest student in Physics class, I just love the way how Physics has answers to almost all of the problems in the Universe. So I decided to try out some basic Physics I learned from school, and it came out pretty well.
I decided to make a simple simulation of the Earth and the Moon revolving around the Earth.
![](https://static.wixstatic.com/media/a09e68_04d9690c129f4fd28b88596c47c7d2d3~mv2.png/v1/fill/w_288,h_98,al_c,q_85,enc_auto/a09e68_04d9690c129f4fd28b88596c47c7d2d3~mv2.png)
![](https://static.wixstatic.com/media/a09e68_50d44a564a234d899e63e4611ee2ad7a~mv2.png/v1/fill/w_579,h_20,al_c,q_85,enc_auto/a09e68_50d44a564a234d899e63e4611ee2ad7a~mv2.png)
void Attract(Attractor AttractorObject)
{
Rigidbody attractorRB = AttractorObject.rb;
Vector3 direction = rb.position - attractorRB.position;
float distance = direction.magnitude;
float forceMagnitude = G * (rb.mass * attractorRB.mass) / Mathf.Pow(distance, 2f);
Vector3 force = forceMagnitude * direction.normalized;
attractorRB.AddForce(force);
}
Comments