Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Prevent sound from playing through walls

Discussion in 'Audio & Video' started by TheAlmightyPixel, Feb 2, 2015.

  1. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Hi all, would anyone happen to know a way to stop sounds from playing through walls? This is a bit problematic for me, as I have a ventilation shaft making noise on the other side of a wall, and I can hear it through the wall when I go to the other side. From what I've heard, FMOD actually has this functionality, but Unity's implementation of FMOD doesn't.
    Suggestions?
     
    afshin_a_1 likes this.
  2. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Sectr Audio
     
  3. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Yeah, I've thought about Sectr Audio, but I'd rather not pay 50$ for the fix..
     
    afshin_a_1 likes this.
  4. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Well, then simply raycast from audiosources to the AudioListener( the player in your case ), and modulate volume if your raycast hits a wall.
     
  5. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Hey! Author of SECTR AUDIO here. Thanks to those who recommended it.

    SECTR Audio supports several different occlusion models, but as gregzo says the simplest thing to do is raycast from source to listener. If you do this you'll probably find that it's too expensive to raycast from every source to the listener every frame. The trick is being able to cast less often and still have smooth sounding audio.

    Happy to answer more questions on SECTR audio if you have them :)
     
  6. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Considering the time you'll need to invest to do this cleanly ( ray casting is just the beginning, you'll also need to handle limit cases and transitions ), SECTR AUDIO is a no brainer. It's a very well made tool and does much more than simply modulating volume.
     
  7. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Thanks for the replies guys.

    As I previously stated, I simply cannot afford to buy Sectr Audio at the moment (I'm a poor student without any income).

    And I understand that the raycasting method is difficult to set up properly, especially as I have many objects in the scene, and I don't want audio to stop playing if the ray hits a trashcan. But I think I might have to create some sort of a system myself for this.
     
    afshin_a_1 likes this.
  8. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Alright, so I figured out a way to do this.
    Basically I used raycasts to see if there is something blocking the view from the Audio Source to the player. But I also made it so that each object can absorb different amounts of sound. Every time the ray hits an object, it gets its occlusion value and muffles the sound based on that value.
     
    CGCowboy, Razputin, Influnza and 2 others like this.
  9. darkAbacus247

    darkAbacus247

    Joined:
    Sep 7, 2010
    Posts:
    251
    Thanks for all reply's, i'll probably check out both suggestions
     
  10. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    We use Projects acoustics, it's amazing, some examples from our game





     
  11. jack_65

    jack_65

    Joined:
    Apr 8, 2021
    Posts:
    8
    You can use sound absorbers in the room to prevent sound in other places.
     
  12. TheArgo

    TheArgo

    Joined:
    Apr 1, 2019
    Posts:
    1
    I'll do you all one better. Create a box collider for each room you are in and make it an is trigger. In that case, your player can walk through the collider. Use an OnTriggerStay script to determine when the player enters the room. If the player is in the room, the volume is enabled. Otherwise, if the player is outside the room, you mute the volume.
     
    SabrinaFoldi likes this.
  13. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,268
    This is a terrible necro, but - SECTR now comes only as a complete package for $100.

    Is there another solution just for audio occlusion?
     
  14. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,868
    There is Master Audio, but that's also $99 if you don't own a previous package of theirs. If you want it for cheap you may need to develop it yourself (I mean depending on how much you feel your time worth), it's not that complex. Or move onto Fmod, in the studio you can set the various curves more easily.
     
    Tom163 likes this.