DrAHIve
About
“DrAHIve” is a rage game that playfully tackles the issue of road safety, making players reflect on how even the smallest, seemingly harmless action can turn fatal.
Project info
👤 Role: Audio and AI Programmer 👥 Team size: 11
⏱︎Time frame: 7 days ⚒︎ Engine: Unity(C#)
Drive through the city to reach your destinations on time, following the markers on your mini-map. Various puzzles will pop up to distract you—solve them before your vision blurs completely.
Audio car engine
The engine audio in “DrAHIve” is an essential part of the player’s experience. It dynamically adjusts based on the car’s speed and direction, creating a more immersive atmosphere. The code focuses on managing the engine sound in response to the car’s movement, such as idle, running, and reversing. It takes into it various factors like engine rev limits and pauses, providing the player with a responsive and realistic sound experience.
The following code snippet illustrates how i handle these dynamic audio adjustments in Unity:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
void FixedUpdate()
{
if (PauseManager.instance.IsPaused)
return;
float speedSign = 0;
if (rb) // Check if the Rigidbody exists
{
speedSign = Mathf.Sign(Vector3.Dot(rb.velocity, transform.forward));
speedRatio = Mathf.Abs(rb.velocity.magnitude / 100f); /* carMovementManager.maxSpeed*/
}
if (speedRatio > LimiterEngage)
{
revLimiter = (Mathf.Sin(Time.time * LimiterFrequency) + 1f) * LimiterSound * (speedRatio - LimiterEngage);
}
if (isEngineRunning)
{
idleSound.volume = Mathf.Lerp(0.1f, idleMaxVolume, speedRatio);
if (speedSign > 0)
{
reverseSound.volume = Mathf.Lerp(reverseSound.volume, 0f, Time.deltaTime);
runningSound.volume = Mathf.Lerp(0.1f, runningMaxVolume, speedRatio);
runningSound.pitch = Mathf.Lerp(runningSound.pitch, Mathf.Lerp(0.3f, runningMaxPitch, speedRatio) + revLimiter, Time.deltaTime);
}
else
{
runningSound.volume = Mathf.Lerp(runningSound.volume, 0f, Time.deltaTime);
reverseSound.volume = Mathf.Lerp(0f, reverseMaxVolume, speedRatio);
reverseSound.pitch = Mathf.Lerp(reverseSound.pitch, Mathf.Lerp(0.2f, reverseMaxPitch, speedRatio) + revLimiter, Time.deltaTime);
}
}
else {
idleSound.volume = 0;
runningSound.volume = 0;
}
}
public IEnumerator StartEngine()
{
FindObjectOfType<AudioManager>().Play("Engine_Start");
carMovementManager.isEngineRunning = true;
yield return new WaitForSeconds(1f);
isEngineRunning = true;
runningSound.source.Play();
idleSound.source.Play();
reverseSound.source.Play();
}
What i learned
I learned the importance of writing clean and efficient code, especially when it is shared and needs to be accessed by others. It helps ensure the codebase remains maintainable and easy to work with.