Ejemplo n.º 1
0
        void Update()
        {
            float kartSpeed = 0.0f;

            if (arcadeKart != null)
            {
                kartSpeed    = arcadeKart.LocalSpeed();
                Drift.volume = arcadeKart.IsDrifting && arcadeKart.GroundPercent > 0.0f ? arcadeKart.Rigidbody.velocity.magnitude / arcadeKart.GetMaxSpeed() : 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));
            }
        }
Ejemplo n.º 2
0
        void Update()
        {
            float kartSpeed = arcadeKart != null?arcadeKart.LocalSpeed() : 0;

            RunningSound.volume = Mathf.Lerp(.1f, 1, kartSpeed / 2);
            RunningSound.pitch  = Mathf.Lerp(.8f, 1.4f, kartSpeed / 4 + Mathf.Sin(Time.time) * .1f);
            IdleSound.volume    = Mathf.Lerp(.5f, 0, kartSpeed);
        }
Ejemplo n.º 3
0
        void Update()
        {
            RPM = arcadeKart != null?Mathf.Abs(arcadeKart.LocalSpeed())  : 0;

            m_DeltaRPM = RPM - m_LastRPM;

            //damp the movement of m_LastRPM
            m_LastRPM = Mathf.Lerp(m_LastRPM, RPM, Time.deltaTime * 100);
            if (Time.timeScale < 1)
            {
                m_Volume = 0;
            }
            else
            {
                m_Volume = 1;
            }
        }
Ejemplo n.º 4
0
        void Update()
        {
            float kartSpeed = arcadeKart != null?arcadeKart.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));
            }
        }
Ejemplo n.º 5
0
        void RotateWheels()
        {
            frontLeftWheel.SetToDefaultRotation();
            frontRightWheel.SetToDefaultRotation();

            float speed         = kartController.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);
        }
Ejemplo n.º 6
0
        void Update()
        {
            // Reset the trigger flag
            if (BounceFlag)
            {
                BounceFlag = false;
            }
            Vector3 origin = transform.position;

            origin.y += HeightOffset;

            for (int i = 0; i < Angles.Length; i++)
            {
                Vector3 direction = GetDirectionFromAngle(Angles[i], Vector3.up, transform.forward);

                if (Physics.Raycast(origin, direction, out RaycastHit hit, RayDistance, CollisionLayer) && Time.time > resumeTime && !hasCollided && kart.LocalSpeed() > 0)
                {
                    // If the hit normal is pointing up, then we don't want to bounce
                    if (Vector3.Dot(hit.normal, Vector3.up) > 0.2f)
                    {
                        return;
                    }

                    // Calculate the incident vector of the kart colliding into whatever object
                    Vector3 incidentVector = hit.point - origin;

                    // Calculate the reflection vector using the incident vector of the collision
                    Vector3 hitNormal = hit.normal.normalized;
                    reflectionVector   = incidentVector - 2 * Vector3.Dot(incidentVector, hitNormal) * hitNormal;
                    reflectionVector.y = 0;

                    kart.Rigidbody.velocity /= 2;
                    // Apply the bounce impulse with the reflectionVector
                    kart.Rigidbody.AddForce(reflectionVector.normalized * BounceFactor, ForceMode.Impulse);

                    // Mark that the vehicle has collided and the reset time.
                    kart.SetCanMove(false);
                    BounceFlag = hasCollided = true;
                    resumeTime = Time.time + PauseTime;

                    audioPlayer.playBounce();
                    //TODO bouncesound
                    //if (BounceSound)
                    //{
                    //    AudioUtility.CreateSFX(BounceSound, transform.position, AudioUtility.AudioGroups.Collision, 0f);
                    //}
                    return;
                }
            }

            if (Time.time < resumeTime)
            {
                Vector3    targetPos      = origin + reflectionVector;
                Vector3    direction      = targetPos - origin;
                Quaternion targetRotation = Quaternion.LookRotation(direction);
                kart.transform.rotation = Quaternion.Slerp(kart.transform.rotation, targetRotation, RotationSpeed * Time.deltaTime);
            }
        }