Geiger Counter or similar.

Hello, Community, I will be brief because English is not my first language.

I need a type of proximity sensor, like a Geiger counter that increase the signal of the sound when the player approaches an object.
But I don’t know how begin. I’m sure it’s an easy b*****t, but for now I’ve tried doesn’t work.Any idea?

Thanks.

Hi Victor,

What you’re probably looking for is distance → volume

What you need first is the distance:

float distance = ( detectingObject.transform.position - playerObject.transform.position).magnitude;

now decide on a maximum distance, let’s use 15f as a “maximum audible distance” then (and you should probably tweak this) here’s a simple linear calculation to transform to audio-volume.

float maximumDistance = 15f;

//...

float geigerCounterVolume = maximumDistance - distance; // this is the distance calculated above;

if ( geigerCounterVolume < 0 ) // it's too far to hear it
  geigerCounterVolume = 0;

geigerCounterVolume = geigerCounterVolume/maximumDistance; // normalize to max volume " 1.0f "

Then simply set the geigerCounter’s AudioSource volume:

geigerCounterObject.audio.volume = geigerCounterVolume;

I hope this helps enough to steer you on your way.

Sure!, very grateful, DarkArts Studios.