Audio volume proportional to distance

0 favourites
  • 8 posts
From the Asset Store
10 different explosions rendered as transparent PNG.
  • Hi!

    In my game, there are many enemies on screen. For each enemy killed, I play the same sound, currently at the same volume.

    Is there a way to set the volume of each killed enemy according to the distance from the player?

    I don't know how to proceed since there is only one audio object, but I suppose there is a way to do so.

    If someone can help... thanks in advance :)

    Rag'

  • I forget the exact formula I used, but I did something like:

    volume = -(distance(object.x,object.y,player.x,player.y) * somefactor)

    If somefactor is higher, the sound will fade out 'faster'.

  • Hi, thanks for taking the time to answer :)

    Actually, my problem is not the formula but the fact that there is only one audio object and many sounds to play at the same time (for the same kind of enemies) with various volumes. <img src="smileys/smiley29.gif" border="0" align="middle" />

  • I had this problem too, I didn't try assigning them random tags, so if there were loads close by, it would play ALL sounds super loud - it's in the patrolling example game in the arcade under 'example games'

    Can't wait for more options with sound, especially panning, so many possibilities with positional stuff gameplay wise.

  • I think C2 should have a "3D Sound" system, where you can make sounds emit from an object, and have an object with the "ears"

  • I forget the exact formula I used, but I did something like:

    volume = -(distance(object.x,object.y,player.x,player.y) * somefactor)

    If somefactor is higher, the sound will fade out 'faster'.

    Can you remember the exact formula I'm having a lot of trouble trying to re-create this. THanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I forget the exact formula I used, but I did something like:

    volume = -(distance(object.x,object.y,player.x,player.y) * somefactor)

    If somefactor is higher, the sound will fade out 'faster'.

    This is the exact formula I use as well. However note that the distance is in pixels so if somefactor == 1 then the sound will fade out very quickly. A good value of somefactor is 0.01

    For readability I write it as a divide...

    volume = -(distance(object.x,object.y,player.x,player.y) / somefactor)

    With somefactor = 100

  • That's exactly what I do.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)