3D sound
- Game Development course
- Intermediate
- Lesson 28/83
- 4 min
Learn 3D sound and distance falloff with Spatial Blend.
3D audio and Spatial Blend
The Spatial Blend property on an AudioSource controls whether audio behaves as 2D or 3D. At 0.0, audio is purely 2D; it sounds equally loud in both stereo ears irrespective of world distance.
AudioSource source = GetComponent<AudioSource>();
// Converting audio into fully spatial 3D sound
source.spatialBlend = 1.0f;At 1.0, audio is purely 3D, panning dynamically across channels based on orientation and location.
Distance attenuation (Rolloff) curves
In 3D audio, volume attenuates as distance from the source increases. minDistance marks the radius of full volume, while maxDistance defines the outer threshold where sound drops to zero.
source.minDistance = 2.0f;
source.maxDistance = 25.0f;
source.rolloffMode = AudioRolloffMode.Logarithmic;The Rolloff Mode dictates whether attenuation diminishes realistically (Logarithmic) or straight-line (Linear).
Practice Print 3D audio settings
Assign "3D" to blend and "Logarithmic" to rolloff. Print SpatialBlend: 3D | Rolloff: Logarithmic to the console.
Starter code
using System;
class Program
{
static void Main()
{
// blend ve rolloff değerlerini tanımlayıp yazdır
}
}Sample solution
using System;
class Program
{
static void Main()
{
string blend = "3D";
string rolloff = "Logarithmic";
Console.WriteLine("SpatialBlend: " + blend + " | Rolloff: " + rolloff);
}
}Expected output
SpatialBlend: 3D | Rolloff: Logarithmic
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What should Spatial Blend be set to for distance-independent 2D sounds such as UI button clicks or music?
- 1.0 (Full 3D)
- 0.5 (Half 3D)
- -1.0 (Inverted)
- 0.0 (Full 2D) Correct answer
Explanation: A Spatial Blend of 0.0 makes the sound purely 2D, ensuring uniform volume regardless of world distances.
2 Set Spatial Blend value
source.____ = 1.0f;
source.spatialBlend = 1.0f;
Explanation: To configure an AudioSource into 3D audio mode, the spatialBlend property is set to 1.0f.
3 3D audio concepts
| Term | Meaning |
|---|---|
Spatial Blend |
Positional blend between 2D and 3D |
minDistance |
Nearest radius heard at full volume |
maxDistance |
Distance where sound fades to silence |
Rolloff |
Volume decay curve over distance |