Search code examples
unity-game-enginegame-physics

Playing same sound on multiple object collide on Unity


I have a Dice rolling game. I have a 6 dice which is applied random force in random direction in a box. Now, when Dice collide with each other as well as within the box wall the sound need to be produced.

Currently when i add sound to each dice and trigger it when the dice collide, the sound is wired when all of them plays at the same time.

Is there a better way to produce the sound like real when all 6 dice collide with each other and with the walls of the box.


Solution

  • The flange-like effect you hear happens when two identical sounds are played with a very small delay causing their wavelengths to amplify and dampen themselves.

    To avoid such effect you have many options:

    1. To just avoid playing same sfx with delays less than inconceivable to user. (you are probably playing each dice hit sfx twice right now)

    2. Use different samples and play them randomly. (if you can't generate new samples try modifying the ones you have by simply changing their pitch by say 3%-10% to have enough different samples)

    3. If second option does not satisfy your need (project size increase) you can use third party plugins such as master audio to create several custom-pitched sounds out of one single sound at run-time.

    4. You can change the pitch in code (at run-time) and make sure two close hits never play with same (or very close) pitch