コード例 #1
0
        void FixedUpdate()
        {
            // Check if there is fuel remaining and stop engine if there is no more fuel to burn
            if (0 >= fuelController.totalFuelRemaining())
            {
                engineRunning         = false;
                calculatedEngineSpeed = 0.0f;
            }

            // Compute engine speed
            if (engineIsStarting)
            {
                calculatedEngineSpeed += 100 / timeForFullEngineSpeed * Time.fixedDeltaTime;

                if (100 <= calculatedEngineSpeed)
                {
                    calculatedEngineSpeed = 100;
                    engineIsStarting      = false;
                }
            }
            else if (engineRunning)
            {
                calculatedEngineSpeed = 100;
            }
            else
            {
                calculatedEngineSpeed = 0;
            }

            // Apply filter on engine speed
            actualEngineSpeed = Mathf.Lerp(actualEngineSpeed, calculatedEngineSpeed, engineSpeedDamping * Time.fixedDeltaTime);
        }
コード例 #2
0
        void Start()
        {
            // Find required components
            rb                  = gameObject.GetComponent <Rigidbody>();
            fuelController      = GetComponent <FuelController>();
            fcPhysicsController = GetComponent <FlightControlsPhysicsController>();

            // Initialize rigidbody's parameters
            rb.useGravity             = true;
            rb.isKinematic            = false;
            rb.drag                   = 0f;
            rb.angularDrag            = angularDrag;
            rb.interpolation          = interpolation;
            rb.collisionDetectionMode = collisionDetection;
            rb.constraints            = RigidbodyConstraints.None;

            float totalWeight = emptyWeight + pilotWeight + copilotWeight + cargoWeight + fuelController.totalFuelRemaining();

            rb.mass = totalWeight / kilograms2pounds;

            rb.inertiaTensor         = inertiaTensor;
            rb.inertiaTensorRotation = inertiaTensorRotation;

            // Compute actual center of mass
            computeCenterOfMass();
        }
コード例 #3
0
        void computeCenterOfMass()
        {
            // empty + pilot + copilot + all fuel tanks + cargo

            float totalWeight = emptyWeight + pilotWeight + copilotWeight + cargoWeight + fuelController.totalFuelRemaining();

            rb.mass = totalWeight / kilograms2pounds;

            Vector3 emptyCenterOfMassPos = transform.position;

            if (null != emptyCenterOfMass)
            {
                emptyCenterOfMassPos = emptyCenterOfMass.position;
            }

            Vector3 pilotPos = transform.position;

            if (null != pilotPosition)
            {
                pilotPos = pilotPosition.position;
            }

            Vector3 copilotPos = transform.position;

            if (null != copilotPosition)
            {
                copilotPos = copilotPosition.position;
            }

            Vector3 cargoPos = transform.position;

            if (null != cargoPosition)
            {
                cargoPos = cargoPosition.position;
            }

            // Actual center of mass is the average of all centers of mass
            Vector3 centerOfMass = transform.InverseTransformPoint(emptyCenterOfMassPos) * emptyWeight;

            centerOfMass += transform.InverseTransformPoint(pilotPos) * pilotWeight;
            centerOfMass += transform.InverseTransformPoint(copilotPos) * copilotWeight;
            centerOfMass += transform.InverseTransformPoint(cargoPos) * cargoWeight;

            foreach (HelicopterSetup.fuelTank tank in fuelController.fuelTanks)
            {
                centerOfMass += transform.InverseTransformPoint(tank.fuelTankPosition.position) * tank.fuelQuantity;
            }

            centerOfMass /= totalWeight;

            rb.centerOfMass = centerOfMass;
        }