Exemplo n.º 1
0
    private void Attract(Body otherBody)
    {
        Vector3 dir      = (otherBody.transform.position - this.transform.position) * scaleManager.GetDistance();
        float   distSqrd = dir.sqrMagnitude;                                                  //Distance in meters

        float   forceMagnitude = scaleManager.GetG() * mass * otherBody.GetMass() / distSqrd; //G * m1 * m2 / d^2
        Vector3 gravForce      = dir.normalized * forceMagnitude;                             //Force in Newtons

        CalcVelocity(gravForce);
        Move();
    }
Exemplo n.º 2
0
    private void Start()
    {
        lastX = this.transform.position.x;
        float axisLength = (orbitAround.transform.position - this.transform.position).magnitude * scaleManager.GetDistance(); //Axis length in m

        //Equation: sqrt(G*M/r)
        localVelocity = Mathf.Sqrt(scaleManager.GetG() * orbitAround.GetComponent <Body>().GetMass() / axisLength) * velocityMultiplier; //Velocity in m/s
        //Debug.Log(localVelocity);
        localVelocity /= scaleManager.GetDistance();                                                                                     //Velocity in AU/s
        velocity       = localVelocity * transform.forward;
    }