protected virtual void Attract(GravityBody gb) { if (gb != null) { Vector3 r_to_this = this.bodyTransform.position - gb.bodyTransform.position; Vector3 force = r_to_this * G_Runtime * gb.rb.mass * this.rb.mass / Mathf.Pow(r_to_this.magnitude, 3); gb.SetForceTo(force); } }
// Attract another gravitational body public void Attract(GravityBody gb) { // Vector from target body to this body Vector3 r_to_this = this.bodyTransform.position - gb.bodyTransform.position; // Newton's law of gravitation Vector3 force = r_to_this * G * gb.GetMass() * this.GetMass() / Mathf.Pow(r_to_this.magnitude, 3); gb.SetForceTo(force); }
// Attract another gravitational body public void Attract(GravityBody gb) { if (gb != null) { Vector3 r_to_this = this.bodyTransform.position - gb.bodyTransform.position; // Newton's law of gravitation Vector3 force = r_to_this * G * gb.rb.mass * this.rb.mass / Mathf.Pow(r_to_this.magnitude, 3); gb.SetForceTo(force); } }