Esempio n. 1
0
    private void Deactivate()
    {
        // Get CM object pos & vel from GE
        GravityEngine ge    = GravityEngine.Instance();
        Vector3d      cmPos = ge.GetPositionDoubleV3(cmNbody);
        Vector3d      cmVel = ge.GetVelocityDoubleV3(cmNbody);

        int i = 0;

        foreach (NBody nbody in nbodies)
        {
            Rigidbody rb = nbody.GetComponentInChildren <Rigidbody>();
            if (rb == null)
            {
                Debug.LogWarning("could not find rigidbody for  " + nbody.gameObject.name);
                continue;
            }
            // rb.isKinematic = true;
            // set position and velocity
            Vector3d nbodyVel = new Vector3d(GravityScaler.ScaleVelSceneToPhys(rb.velocity));
            ge.SetVelocityDoubleV3(nbody, cmVel + nbodyVel);
            Vector3d nbodyPos = new Vector3d(GravityScaler.ScalePositionSceneToPhys(nbody.transform.localPosition));
            ge.SetPositionDoubleV3(nbody, cmPos + nbodyPos);
            ge.ActivateBody(nbody.gameObject);
            // restore parent
            nbody.transform.parent = priorParents[i];
            i++;
        }
        ge.RemoveBody(cmObject);
        Destroy(cmObject);
        // de-activate any RCS elements
        foreach (ReactionControlSystem r in rcs)
        {
            if (r != null)
            {
                r.SetRigidBodyEnabled(false);
            }
        }
    }