예제 #1
0
    void Attract(Gravityss PlanetToAttract)
    {
        Rigidbody rbToAttract = PlanetToAttract.rb;                                     //considers the attracting planet as a rigidbody

        Vector3 displacement = rb.position - rbToAttract.position;                      //calculates the displacement between planets
        float   seperation   = displacement.magnitude;                                  //calculates the seperation of planets

        ForceMagnitude = ((rb.mass * rbToAttract.mass) * G) / Mathf.Pow(seperation, 2); //calculates the magnitude of the gravity

        Vector3 force = displacement.normalized * ForceMagnitude;                       //converts the force into a vector

        rbToAttract.AddForce(force);                                                    //adds the force vector
        Accel = ForceMagnitude / 330000;
    }
예제 #2
0
 void EllipticalOrbit(Gravityss PlanetToAttract)
 {
     Vector3 displacement = rb.position;
     float   seperation   = displacement.magnitude;
 }