ProjectStorms.AirshipControlBehaviour.CalculateRightingForce C# (CSharp) Method

CalculateRightingForce() private method

Attempts to auto-level the player's ship. Counters roll more-so than pitch, ignores yaw.
private CalculateRightingForce ( ) : void
return void
        private void CalculateRightingForce()
        {
            // Calculate a few useful vectors relative to the ship and the world
            Vector3 worldUp = new Vector3(0, 1, 0); // Up relative to the world
            Vector3 shipForward = m_trans.forward; // Front relative to the ship
            Vector3 shipRight = m_trans.right; // Right relative to the ship

            var torque = Vector3.zero;

            // Roll
            float rollDot = Vector3.Dot(worldUp, shipRight);
            torque += -rollDot * shipForward * rollForce * rollLimitMult;

            // Pitch
            float pitchDot = Vector3.Dot(-worldUp, shipForward);
            torque += -pitchDot * shipRight * pitchForce * pitchLimitMult;

            // Add all the torque forces together
            m_myRigid.AddTorque(torque);
        }