Exemplo n.º 1
0
 public int CalculateSourceRank(int count)
 {
     if (CurrentGravitySource == null)
     {
         return(count);
     }
     return(CurrentGravitySource.CalculateSourceRank(count + 1));
 }
Exemplo n.º 2
0
    private void UpdateIteratively()
    {
        // Gravitational force
        Vector2 gravitationalForce = CurrentGravitySource.CalculateGravitationalForceAtPosition(transform.position, Mass);

        body.AddForce(gravitationalForce);

        // Other forces
        ApplyNonGravitationalForces();

        Vector2 relVel = Velocity - CurrentGravitySource.Velocity; // world vel - newSource.vel
        Vector2 relPos = Position - CurrentGravitySource.Position; // world pos - newSource.pos

        CalculateOrbitalParametersFromStateVectors(relPos, relVel);
    }
Exemplo n.º 3
0
    private void UpdateCurrentGravitySource()
    {
        if (recentlyChangedSource)
        {
            return;
        }

        if (LeavingSphereOfInfluence() && CurrentGravitySource.CurrentGravitySource != null) // Leaving current source
        {
            Debug.LogFormat("{0}'s leaving {1}'s sphere of influence. Entering {2}'s.", gameObject.name, CurrentGravitySource.name, CurrentGravitySource.CurrentGravitySource.name);
            InitializeNewOrbit(CurrentGravitySource.CurrentGravitySource);
        }
        else
        {
            GravitySource dominantGravitySource = CurrentGravitySource.GetGravitySourceAtPosition(Position, true);
            if (dominantGravitySource != CurrentGravitySource)
            {
                Debug.LogFormat("{0}'s leaving {1}'s sphere of influence. Entering {2}'s.", gameObject.name, CurrentGravitySource.name, dominantGravitySource.name);
                InitializeNewOrbit(dominantGravitySource);
            }
        }
    }