예제 #1
0
    private void Start()
    {
        // Cache transform
        trans = transform;
        // Cache & set up rigidbody
        rb             = GetComponent <Rigidbody>();
        rb.drag        = 0;
        rb.useGravity  = false;
        rb.isKinematic = false;

        // Bail out if we don't have an object to orbit around
        if (orbitAround == null)
        {
            Debug.LogWarning("Satellite has no object to orbit around");
            return;
        }

        // Update the ellipse with initial value
        if (ellipse == null)
        {
            Reset();
        }
        ellipse.Update(orbitAround.position, transform.position, apsisDistance, circularOrbit);

        // Calculate starting orbit state
        orbitState = new OrbitState(startingAngle, this, ellipse);

        // Position the orbiter
        trans.position = ellipse.GetPosition(startingAngle, orbitAround.position);

        // Add starting velocity
        rb.AddForce(orbitState.velocity, ForceMode.VelocityChange);
        StartCoroutine("Orbit");
    }
예제 #2
0
 // Update the state of the orbiter when its position along the ellipse changes
 // Note: Make sure the ellipse is up to date before updating the orbit state
 private void Update(float orbiterAngle, Orbiter orbiter, OrbitalEllipse ellipse)
 {
     this.orbiter  = orbiter;
     this.ellipse  = ellipse;
     this.normal   = CalcNormal(orbiterAngle);
     this.tangent  = CalcTangent(normal);
     this.position = ellipse.GetPosition(orbiterAngle, orbiter.orbitAround.position);
     this.velocity = CalcVelocity(orbiter.orbitSpeed * orbiter.GravityConstant(), position, orbiter.orbitAround.position);
 }