Hi,
In my fist person shooter, I’m using AudioSource.PlayClipAtPoint
to indicate an enemy spawn. It’s important that the player hears this sound, in 3D, so that he has an indication of where the enemy spawns.
This works fine, but since the enemy is far away, the volume of the sound is very low.
Is there a way to make unity ignore the distance, but keep the 3D sound capacities so that one could still tell whether the enemies spawn behind/above/… them?
I handled this now by reducing the other volumes, for example of the gun firing, to 0.05. But this makes the game overall real quiet, of course.
Any help is much appreciated!
Probably the easiest way to do this is to make a proxy sound source for the distant object that is actually much closer, but in the same exact direction. This would be a blank GameObject with AudioSource on it that you would move around to be where you want it.
If the player (listener) is at p1 and the sound source is at p2, then you can position the proxy sound source at:
const float DistanceToProxySound = 5.0f;
Vector3 proxySoundPosition = p1 + (p2 - p1).normalized * DistanceToProxySound;
The only problem with that is that if the source is CLOSER than the 5.0, the proxy will still be at a range of 5.0, so you can also check for that and if the source is closer than the proxy range, just use the source’s location.
That’s pretty smart, we didn’t I think of that? Thanks!!!
1 Like
You can just use the audiosource curve to adjust the volume/distance audio falloff and position the audiosource exactly where the enemy is.
And yeah, I would have a pool of empty game objects with audiosources attached, and child them to objects or move them where they need to be and just play audio when you need it from those instead of using PlayClipAtPoint (because it doesn’t handle most use cases, but the other method does).
1 Like