meta xr, auto fix, occlusion additions
This commit is contained in:
@@ -24,6 +24,9 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
private bool stopSoundPlayed = false;
|
||||
private float stopThreshold = 0.05f; // consider speed "0" when below this
|
||||
|
||||
private bool isBeingStoppedByPlayer = false;
|
||||
|
||||
|
||||
[Header("Tires")]
|
||||
public List<GameObject> FrontTires;
|
||||
public List<GameObject> BackTires;
|
||||
@@ -54,25 +57,26 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
|
||||
rollTires(); // Just an aesthetic improvement.
|
||||
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) > 1f) // If the car is turning.
|
||||
if (!isBeingStoppedByPlayer)
|
||||
{
|
||||
if (!isTurning)
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) > 1f)
|
||||
{
|
||||
AudioController.SetRPM(1300); //set externally in CarAudioController.cs
|
||||
setTireRotation(tireTurnAngle);
|
||||
if (!isTurning)
|
||||
{
|
||||
setTireRotation(tireTurnAngle);
|
||||
AudioController.SetRPM(1300);
|
||||
}
|
||||
isTurning = true;
|
||||
}
|
||||
|
||||
isTurning = true;
|
||||
}
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) <= 1f) // Reset the turn value.
|
||||
{
|
||||
if (isTurning)
|
||||
else
|
||||
{
|
||||
AudioController.SetRPM(1450);
|
||||
setTireRotation(-tireTurnAngle);
|
||||
if (isTurning)
|
||||
{
|
||||
setTireRotation(-tireTurnAngle);
|
||||
AudioController.SetRPM(1450);
|
||||
}
|
||||
isTurning = false;
|
||||
}
|
||||
|
||||
isTurning = false;
|
||||
}
|
||||
|
||||
// Check if close enough to the waypoint
|
||||
@@ -85,12 +89,14 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
|
||||
if (StraightSpeed <= stopThreshold && !stopSoundPlayed)
|
||||
{
|
||||
stopSoundPlayed = true;
|
||||
|
||||
// Play the sound normally from your audio controller
|
||||
//AudioController.SetRPM(475);
|
||||
AudioController.PlayStopSound();
|
||||
|
||||
float currentRPM = AudioController.GetCurrentRPM();
|
||||
//Debug.LogError(currentRPM);
|
||||
if (currentRPM <= 550f) // confirms we are in the correct engine state
|
||||
{
|
||||
stopSoundPlayed = true;
|
||||
AudioController.PlayStopSound();
|
||||
//Debug.LogError("piiks");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,29 +126,29 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{;
|
||||
{
|
||||
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
||||
StartCoroutine(SmoothAdjustSpeed(0, 0, haltspeed)); // Smoothly halt in 1 second
|
||||
//_tireSound.Stop();
|
||||
//_stopSound.Play();
|
||||
|
||||
isBeingStoppedByPlayer = true;
|
||||
|
||||
StartCoroutine(SmoothAdjustSpeed(0, 0, haltspeed));
|
||||
|
||||
AudioController.SetRPM(475);
|
||||
//AudioController.PlayStopSound();
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
||||
StartCoroutine(SmoothAdjustSpeed(targetSpeed, targetRotationSpeed, haltspeed)); // Smoothly resume speed in 1 second
|
||||
//_stopSound.Stop();
|
||||
//_tireSound.Play();
|
||||
|
||||
isBeingStoppedByPlayer = false;
|
||||
|
||||
StartCoroutine(SmoothAdjustSpeed(targetSpeed, targetRotationSpeed, haltspeed));
|
||||
|
||||
AudioController.SetRPM(1450);
|
||||
stopSoundPlayed = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator SmoothAdjustSpeed(float targetStraightSpeed, float targetRotationSpeed, float duration)
|
||||
{
|
||||
float initialStraightSpeed = StraightSpeed;
|
||||
|
||||
@@ -4,6 +4,7 @@ using FMOD.Studio;
|
||||
public class CarAudioController : MonoBehaviour
|
||||
{
|
||||
private EventInstance carMovementInstance;
|
||||
private EventInstance carStopInstance;
|
||||
private FirstPersonOcclusion occlusion;
|
||||
|
||||
private void Awake()
|
||||
@@ -15,13 +16,21 @@ public class CarAudioController : MonoBehaviour
|
||||
//Debug.LogError("Car Simple Driving:");
|
||||
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
|
||||
carMovementInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.CarModulatedDriving);
|
||||
carStopInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.BoltCarStopSound);
|
||||
|
||||
carMovementInstance.setParameterByName("RPM", 1450);
|
||||
carMovementInstance.setParameterByName("Load", 0);
|
||||
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
carStopInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
|
||||
occlusion = GetComponent<FirstPersonOcclusion>();
|
||||
|
||||
if (occlusion != null)
|
||||
occlusion.InitialiseWithInstance(carMovementInstance);
|
||||
{
|
||||
occlusion.InitialiseWithInstance(carMovementInstance); // main looping engine sound
|
||||
occlusion.AddInstance(carStopInstance); // additional sound
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -34,6 +43,7 @@ public class CarAudioController : MonoBehaviour
|
||||
{
|
||||
// Always update 3D position to follow the car model transform
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
carStopInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
}
|
||||
|
||||
// These methods are called externally by CarDrivingRoutine
|
||||
@@ -44,8 +54,13 @@ public class CarAudioController : MonoBehaviour
|
||||
|
||||
public void PlayStopSound()
|
||||
{
|
||||
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.BoltCarStopSound, gameObject);
|
||||
carStopInstance.start();
|
||||
//AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.BoltCarStopSound, gameObject);
|
||||
|
||||
}
|
||||
public float GetCurrentRPM()
|
||||
{
|
||||
carMovementInstance.getParameterByName("RPM", out float value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user