void FixedUpdate() { float rotationSpeed = rigidbody.angularVelocity.magnitude; rotationAudioSource.volume = AudioAdjustmentSettings.ClampAndInterpolate(rotationAudioSource.volume, rotationSpeed, k_Volume); rotationAudioSource.pitch = AudioAdjustmentSettings.ClampAndInterpolate(rotationAudioSource.pitch, rotationSpeed, k_Pitch); }
void FixedUpdate() { m_IsGrounded = Physics.Raycast(m_Rigidbody.position, Vector3.down, distanceToGround); m_Speed = m_Rigidbody.velocity.magnitude; if (m_IsGrounded) { rollingAudioSource.volume = AudioAdjustmentSettings.ClampAndInterpolate(rollingAudioSource.volume, m_Speed, k_GroundedRollingVolume); rollingAudioSource.pitch = AudioAdjustmentSettings.ClampAndInterpolate(rollingAudioSource.pitch, m_Speed, k_GroundedRollingPitch); } else { rollingAudioSource.volume = Mathf.Lerp(rollingAudioSource.volume, k_AirborneRollingTargetVolume, k_AirborneRollingVolumeChangeRate * Time.deltaTime); rollingAudioSource.pitch = Mathf.Lerp(rollingAudioSource.pitch, k_AirborneRollingTargetPitch, k_AirborneRollingPitchChangeRate * Time.deltaTime); } movementAudioSource.volume = AudioAdjustmentSettings.ClampAndInterpolate(movementAudioSource.volume, m_Speed, k_MovementVolume); movementAudioSource.pitch = AudioAdjustmentSettings.ClampAndInterpolate(movementAudioSource.pitch, m_Speed, k_MovementPitch); }
public static float ClampAndInterpolate(float value, float speed, AudioAdjustmentSettings settings) { float speedBasedRollingVolume = Mathf.Clamp(speed * settings.speedTo, settings.min, settings.max); return(Mathf.Lerp(value, speedBasedRollingVolume, settings.changeRate * Time.deltaTime)); }