示例#1
0
        void Update()
        {
            float kartSpeed = car != null?car.LocalSpeed() : 0.0f;

            IdleSound.volume = Mathf.Lerp(0.6f, 0.0f, kartSpeed * 4);

            if (kartSpeed < 0.0f)
            {
                // In reverse
                RunningSound.volume = 0.0f;
                ReverseSound.volume = Mathf.Lerp(0.1f, ReverseSoundMaxVolume, -kartSpeed * 1.2f);
                ReverseSound.pitch  = Mathf.Lerp(0.1f, ReverseSoundMaxPitch, -kartSpeed + (Mathf.Sin(Time.time) * .1f));
            }
            else
            {
                // Moving forward
                ReverseSound.volume = 0.0f;
                RunningSound.volume = Mathf.Lerp(0.1f, RunningSoundMaxVolume, kartSpeed * 1.2f);
                RunningSound.pitch  = Mathf.Lerp(0.3f, RunningSoundMaxPitch, kartSpeed + (Mathf.Sin(Time.time) * .1f));
            }
        }
示例#2
0
        void RotateWheels()
        {
            frontLeftWheel.SetToDefaultRotation();
            frontRightWheel.SetToDefaultRotation();

            float speed         = carController.LocalSpeed() * 10f;
            float rotationAngle = speed * Time.deltaTime * m_InverseFrontWheelRadius * Mathf.Rad2Deg;

            frontLeftWheel.TurnWheel(rotationAngle);
            frontRightWheel.TurnWheel(rotationAngle);

            rotationAngle = speed * Time.deltaTime * m_InverseRearWheelRadius * Mathf.Rad2Deg;

            rearLeftWheel.TurnWheel(rotationAngle);
            rearRightWheel.TurnWheel(rotationAngle);

            frontLeftWheel.StoreDefaultRotation();
            frontRightWheel.StoreDefaultRotation();

            rotationAngle = m_SmoothedSteeringInput * maxSteeringAngle;
            frontLeftWheel.SteerWheel(rotationAngle);
            frontRightWheel.SteerWheel(rotationAngle);
        }