Audio volume proportional to distance

Get help using Construct 2

Post » Thu Aug 09, 2012 10:15 am

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'
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Thu Aug 09, 2012 11:42 am

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'.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Aug 09, 2012 9:06 pm

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. Ragtime2012-08-09 21:55:36
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Thu Aug 09, 2012 10:04 pm

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.JohnnySix2012-08-09 22:05:36
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Fri Aug 10, 2012 3:17 am

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"
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Tue Oct 23, 2012 8:17 pm

[QUOTE=sqiddster] 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'.[/QUOTE]

Can you remember the exact formula I'm having a lot of trouble trying to re-create this. THanks
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Tue Oct 23, 2012 10:07 pm

[QUOTE=sqiddster] 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'.[/QUOTE]

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
B
11
S
4
G
3
Posts: 70
Reputation: 3,071

Post » Tue Oct 23, 2012 11:19 pm

That's exactly what I do.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, jeffige and 1 guest