Esempio n. 1
0
        public void UpdateEngine(Rigidbody rb, XP_Drone_Inputs input)
        {
            //Debug.Log("Runing Engine: " + gameObject.name);
            Vector3 upVec = transform.up;

            upVec.x = 0f;
            upVec.z = 0f;
            float diff      = 1 - upVec.magnitude;
            float finalDiff = Physics.gravity.magnitude * diff;

            Vector3 engineForce = Vector3.zero;

            //engineForce = transform.up * ((rb.mass * Physics.gravity.magnitude) + (input.Throttle * maxPower))/4f;

            // auto hover : additional force to compensate inclination
            engineForce = transform.up * ((rb.mass * Physics.gravity.magnitude + finalDiff) + (input.Throttle * maxPower)) / 4f;

            rb.AddForce(engineForce, ForceMode.Force);
            //rb.AddRelativeForce(engineForce);

            Debug.DrawLine(rb.position, transform.up, Color.white, 0f);
            Debug.Log(rb.centerOfMass);

            HandlePropellers();
        }
 void Start()
 {
     input   = GetComponent <XP_Drone_Inputs>();
     engines = GetComponentsInChildren <IEngine>().ToList <IEngine>();
 }