Play Random Sound for the Same Object

Get help using Construct 3!

Post » Wed Jul 05, 2017 3:25 am

In Construct 2 is there a way to make it so the same object plays multiple sound files when the same action happens? So when I hit or attack something it plays multiple sound files?
B
6
S
1
Posts: 3
Reputation: 358

Post » Wed Jul 05, 2017 8:19 am

Do you mean that on the same event e.g. Object A collides with Object B, a random sound will be played?

If so, one way to do this is to give your sounds a set of indexed filenames like sfx_0, sfx_1, sfx_2.

Then on your trigger event use the audio action "play (by name)"; in the audio file name field write: "sfx_"&choose(0,1,2)

You could of course use choose with non-indexed file names e.g. choose("bang","laser","grenade"), but indexing gives you more flexibility, especially if you have a lot of sounds to pick between - you may even want to switch from using choose() to floor(random(min,max)) as this would allow you even more control over what was played.

For bonus variation add the "Set playback rate" action directly underneath this action, setting the playback rate to a random number.
B
19
S
8
G
3
Posts: 432
Reputation: 3,978

Post » Sat Jul 08, 2017 4:18 am

thats actually pretty smart. id've told you to set a variable for sound played, but then youd have to say 1 = sound1 2 = sound2 3=sound3, where as indexed names you can say "sound"&Random(x,y) and it solves for the whole lot.
B
22
S
12
G
1
Posts: 108
Reputation: 2,774


Return to How do I...?

Who is online

Users browsing this forum: Bootfit and 0 guests