top of page
Search
Writer's pictureAbishek J Reuben

Trying out real life physics simulations inside Unity


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.




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);

}

65 views0 comments

Recent Posts

See All

Comentarios


bottom of page