Hi there! Does anyone know how we can make 2D Audio ‘fade’ with distance of the audio source (as the camera gets away from it), I am aware of the ‘spatial blend’ slider in Unity audio source; when I select that and put it as ‘3D audio’ (on the right), the sound becomes worse (quality wise) it has 3D depth and sound fading by distance; as soon as return to 2D on the (same) spatial blend slider; now the sound is always loud not matter the distance to the sounds in the scene. Effectively, 2D, just like playing the SFX…straight with no processing.
And that’s exactly what I am looking for - no processing by the spatial blend (because it worsens the quality of the audio; when with 3D spatial blend 100%, I detected loss of ‘surround harmonics dynamics/noise depth’ in the original flac file- due to the spatial processing ‘3difying’ the sfx file; as such it might be 3D’ed but quality takes a drop and sound does not sound like original HQ flac; it’s subtle but there (the original is Bright/surround/dynamic; the 3D sounds muddied/lowified/lowresed/lost original surround harmonics);
I only wish to have the sound to sound the very same as original file; not have degradation by 3D audio processing), but the problem is that the 2D sound is always loud/at 100% volume all the time and never ‘fades’ with distance - as 2D (on the slider)…thus, I am looking to make 2D sound (not 3D spatial blend) that fades (reduces in volume or augments in volume) depending on how close/how far is audio listener to the audio source in the scene. Is this even possible, it sounds simple enough, just make the audio volume louder/quieter -depending on distance of audio listener to audio source ‘to fake audio volume dropping with distance and rising when closing-in’; is there such a script that exists? There has to be a tool that allows to control *2D volume level by distance (and that the sound, remains 2D, - at all distances; it’s only its volume that changes by distance). Any takers/Any ideas? Thank you for any help.
you can try first spacial blend with 180 degrees of spread (half way), the 3D sound is evenly spread between the speakers. and change the compression which is usually the cause of audio quality issue
The other option is set the volume based on distance between audio listener and audio source from script
something like this
to assign script to audio listener you can use something like this. I chose to do it with tags as they are more efficient to search. You have to assign tag "AudioSources"to each object with audio source which you want to be handled by this script. I am writing it in notepad only so sorry if there are any wrong upper lower case or typo.
public AudioSource[] audioSources;
public float maxDistance = 10f; //distance to became volume 0
float distanceToTarget;
void Update(){
audioSources= GameObject.FindGameObjectsWithTag("AudioSources").GetComponent<AudioSource>();
//instead of search everytime you can also assign them in the editor and remove this line.
//Which would be more efficent if they exist already in scene.
foreach(AudioSource audioSource in audioSources){
distanceToTarget = Vector3.Distance(transform.position, audioSource.transform.position);
audioSource.volume = 1 - (distanceToTarget/maxDistance);
}
}
The first options still process the audio (and thus reduce quality), same with compression (I tried all of them, vorbis, adpcm and pcm; but they all change it; despite being touted ‘uncompressed’ pcm; it still changes the flac (because these compressions are not flac compression; but are WAV based which is lossless; while flac might be lossless; it still sounds different than an uncompressed WAV; a flac file can ‘add’ noise/harmonic distortion to a sound file; something you normally would not want; but in some cases, you do; and the WAV/PCM removes it; while ADPCM, is kind of the inbetween; it surprisingly is more accurate to the flac; than PCM; because it keeps more of that distortion and is a lossy compressed format), thus, I am intrigued by your script suggestion;
On what would we put that, the audio source (I am thinking) or…the audio listener; of course it would really better on an audio listener (just set and forget, once…on the camera…and done with…) ratehr than having to put that script - on each - audio source/SFX…
Also these 2 lines would be part of a script; if you were in my place (and had less coding knowledge that your current case) and you wished to make what I asked; what else would need to be added on this script - to add it straight to audio listener or audio source (i.e. I understand that these code lines are what drives volume - distance; how do we put it on audio source/what else is there to ‘add’ to make a fully working script) Thank you/sorry for annoying you for more!