- Home /
Audio mixed, blending on distance ?
Hello,
I want to get the following effect: In a room is an object, lets say e.g a musical clock that plays a distorted silent melody.
If I move towards this audio source it gets louder and more clear getting rid of those distortions. so the audio source's volume reacts to distance of the player to the object My idea was that I could make two soundfiles one clear one distorted and while moving towards the musical clock both files get mixed, blended into one.
example:
player distance from object 90% -> audio (distorted) 100% audio (clear) 0% overall audio 10%
player distance from object 50% -> audio (distorted) 50% audio (clear) 50% overall audio 50%
player distance from object 10% -> audio (distorted) 0% audio (clear) 100% overall audio 90%
I would be very pleased if you could help me out or at least give me some hints (:
Wish you a lovely day!
Answer by sneftel · Jun 20, 2011 at 02:17 PM
Sure, you can do this pretty easily -- just have two AudioSource
s, and set the volume on each one based on the player's distance. You can use something like Mathf.Clamp01((dist-minDist)/(maxDist-minDist))
to convert from a distance to a ratio.
However, if you have Unity Pro, you should also consider using the various audio filter components (e.g. AudioDistortionFilter
) instead.
thank you :)
I'll check the filters out.
How do I implement your line in any code?
Could someone give an example perhaps?
I've got nearly zero experience in coding :(