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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Making sounds that are outside a building sound like they are outside

Discussion in 'Audio & Video' started by KnightsHouseGames, Mar 13, 2016.

  1. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    I'm making a game that is extremely dependant on good sound design for immersion purposes, as well as for telling the player where they are (the game has no graphics).

    What I'd like to do is be able to make locations that are indoors like buildings and caves distort sounds that are coming from outside, and make it so sounds that are really far away from the player reverb and distort like sounds that are far away.

    I'm using Unity 4 right now still, since I started the project in Unity 4, is Unity 4 capable of such effects? I know reverb zones exist, but I can only get them to effect things that are inside of the area, not outside of it.
     
  2. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    Unity 5 has a ton of effects that could easily help you with this, like Low Pass and High Pass filters, distortion, eq etc. It is very easy to do these in Unity 5. Much more difficult to do it in 4, though others may have opinions about that. For what it's worth, I upgraded to 5 in the middle of a project, it was super simple and nothing broke. I made a backup of the project in case it didn't work, but I didn't need it and I happily completed the project in 5.

    B
     
  3. Sylux102

    Sylux102

    Joined:
    Mar 17, 2013
    Posts:
    15
    As said above U5 is very useful for this kind of thing.

    However, if you dont want to upgrade, you could do what the old Bungie Halo games did. You have two of every sound. One regular, and one muffled. Then you do some sort of check (IE, distance/raycast) to see how far and if there's a direct line of sight to the sound. Depending on the result of that check, you then play the appropriate audio clip (regular or muffled). This will, however, increase end game file size, so be wary what sounds you want to use it for.
     
  4. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    Well, I guess I'll have to upgrade to Unity 5 then, I do vaguely remember seeing in the U5 trailer that it had some pretty awesome sound tools

    That would also require twice as much work and possibly more recordings than I've already done, In addition to the increased end game file size, it seems like it would be a lot more work than just bucking up, upgrading, and learning how to use the new system

    Should I expect a lot of growing pains with this new editor or is it pretty much the same?
     
  5. Sylux102

    Sylux102

    Joined:
    Mar 17, 2013
    Posts:
    15
    U5 is pretty much the same. The code has changed, some of your code might break. Just read the documentation, it'll be all good.

    And it wouldn't bee all that much work. Just take whatever sounds you want muffled and throw them through a low pass filter in some sound editor. Tweak to your likeness and then just plug and play the sounds and export them. No re-recording required.
     
  6. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    I'll have to investigate that. And how has the code changed? I use C#, what will I need to worry about?

    That is one thing I'm still not sure about, how would I achieve this effect once in Unity 5? Is there some way to apply these filters and then switch them on and off on the fly? My buildings and outdoor areas are in the same scene

    And how would I apply filters to distant sounds reletive to the player?

    Edit: Yikes.....the breaking stuff thing.....now I see what you mean o_o

    I wish it hadn't broken my Unity 4 install in the process... Looks like I'm committed to Unity 5 now....

    I've got some damage control to do
     
    Last edited: Mar 13, 2016
  7. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    To apply your filters on the fly, check the location of the player and apply the filters accordingly. There are a lot of ways to do this, but the simplest way might be to have a switch that represents "inside" and "outside" on the player. When the switch is on "inside", apply the filter, when it is "outside", turn the filter off.

    Have a good read of the Audio section of the manual, it really is very detailed.

    As for your upgrade, if you want to go back, you can download Unity 4 from
    http://unity3d.com/get-unity/download/archive

    ,open your backup and you're back where you started. If you didn't make a backup, you're committed to 5.

    In 4, you can either do what Sylux102 suggested, have two versions of each sound or, from memory, Unity4 does have reverb zones, so you could do a basic version of occlusion by turning down the high pass reverb.

    B
     
  8. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    Interesting, thats a good idea, I'll try that. I've been messing around for the last few hours looking at how this new mixer system works and it really is quite awesome, there are still a few little things that are broken in my project, but there are also new things here that are signifcantly better

    Yeah, I'm watching Unity's video tutorials on it all, it's very interesting. I'm starting to get some ideas on how I might want to try to do a few things

    All I'm regretting now is not switching to 5 when I started this project so I wouldn't have to live through all these growing pains of this switchover, and maybe my previous install of Unity 4 could have survived

    I'll reinstall when I'm feeling a little braver about it, right now I just wanna make my current project work. My backup was done wrong, so I am pretty much commited at this point, but maybe thats not a terrible thing completely. That being said, I would like an install of Unity 4 so I can still work on my older projects

    But is there a way to make reverb zones effectively work backwards? It seems to me that the closer you are to the center of a reverb zone, the more it comes into effect, not the other way around. If I want stuff far away from the character to sound far away, is there a way to make stuff far away from the character reverb, while things that are close make more normal sounds?

    Thanks for all this by the way, you've been extremely helpful so far
     
  9. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    If I understand your question correctly, you would position the reverb zone at the place where you want to hear the most reverb. For example, if you want to hear the reverb only when inside the cave, place the reverb zone in the cave with a minDistance the size of the cave.

    B
     
  10. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    I mean more like...hmm...how do I describe it

    Like, if you've ever played The Last of Us, in the outdoor settings in the game, when the bad guys are really far away, you get that reverb of their yelling and their gunshots so it sounds like the sound is comming from far away. They do the same thing with characters voices and such if your outside and wander too far away from whoever is talking, but when you are close to them, it sounds normal

    So the idea would be I'd want to put a sphere like a reverb zone around my character, but invert it, so that everything inside of the sphere didn't have reverb, and everything outside of it does.
     
  11. Sylux102

    Sylux102

    Joined:
    Mar 17, 2013
    Posts:
    15
    You could use AudioReverbFilter for this effect, no? Just apply it to whatever audio sources outside a certain distance.

    EDIT: You could tie the reverberation amount to the distance between the audio listener and the audio source.
     
  12. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    Ohh, clever

    Would I do that with a send perhaps? And what do you think would be the best approach to linking that to that distance?
     
  13. Sylux102

    Sylux102

    Joined:
    Mar 17, 2013
    Posts:
    15
    Depends on what you're doing in your game.

    Some pseudo code I'd use is something like this:

    var audioSrc
    var audioListener
    var dist = Vector3.Distance(audioSrc.transform.position, audio listener.transform.position)

    audioSrc.reverbAmount = dist.normalized

    Obviously this code would not work plugged in directly, but it does show how the wanted effect can be achieved.
     
  14. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    I'll do some research and see if I can figure this out with what you've given me, I'll let you know how it turns out
     
  15. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    So it took me a while, but I worked out something pretty cool

    I did some research and some math and figured out some relationships between sound and distance, and used that to develop an algorithm that would allow them to translate distance to volume.

    Using a reletive scale factor, I can alter the amount of distance in which the effect takes place. Based on distance, the attenuation of the mixer group goes down, while the send volume to the effect group goes up. With this relationship, I can use the scale factor number to alter how far away and how severe with reverb, high pass, and low pass filters will effect the sound on that mixer group. If you make the scale number high, the effects will be more granular and more realistic over long distances. If you make the scale number low, the effects will be more immediate and up close for some interesting effects

    Now I'm just trying to figure out how to apply this function to an event system that I can have trigger for all the ambiant sound generators each time the player takes a step
     
  16. Sylux102

    Sylux102

    Joined:
    Mar 17, 2013
    Posts:
    15
    This could be done with layers. Apply said effect only to audio instances on a certain layer, and ignore everything else.

    You likely wouldn't want to call this on all audio instances in a scene every frame, as this could get very expensive. What I'd do is find a certain distance where the audio plays normally without any effect and disable the script on those. Then find the max distance where the effects levels don't change (aside from volume) and disable the calculations on those as well. That would essentially cut down on the amount of work the audio system is trying to do.

    Maybe something like:

    var minDist
    var maxDist

    if(Vector3.Distance(player.position, audio source.
     
  17. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    I think I see what you're saying as far as not calling it on every frame and such, but I was thinking of calling it on steps instead (I should clarify, in this game, a step is something of a distinct action the player can take. So walking isn't like in a normal game where it's something of a constant translation, so much as it is more like grid movement, so the act of taking a step is a coroutine that only runs once at a time and causes the player to take a single step of a set distance, so theres significant time between each call).

    That min/max distance thing could be good though, I haven't really built a huge level yet with a lot of different sound generators, so I hadn't thought about how that could effect a larger room. I'm betting I could even figure out a way to make those min/max values scale with my scale factor value though, so I'll have to try and throw something together that utilizes that