示例#1
0
 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);
     }
 }
示例#2
0
    // 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);
    }
示例#3
0
    // 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);
        }
    }