Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
3 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bobbybob · Mar 02, 2012 at 12:28 AM · audiosoundspherewall

Sound through wall / Audio zones

Hi there, I have an issue implementing some of my sounds.

For exemple, I have a cubic room. Against one of the wall there is a Hifi playing sounds. When I am in the room, I can hear the Hifi and the sound's volume goes down as I move away from it. So far so good. The only thing is that on the other side of the wall (in another room), I can still hear the Hifi as if the wall wasn't there! The sound should be off or at least really softer.

I don't know how to fix this since I can only deal with spheric audio zones.

Thank you in advance for reading me and helping me out!

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Mar 02, 2012 at 12:40 AM 0
Share

Worst part is, F$$anonymous$$OD has this functionality out of the box- it's just that Unity doesn't have any interface to it, and so you can't implement the native F$$anonymous$$OD solution. You need to rely on hacks like audio zones.

avatar image DaveA · Mar 02, 2012 at 01:18 AM 0
Share

I know this doesn't help you now, but I'll be releasing a rather cool audio toolkit in the Asset store in a couple months that would take care of this for you.

avatar image hrlarsen · Mar 02, 2012 at 09:25 AM 0
Share

Im having the exact same problem at the moment, I have tried to do this using RayCast but I cannot get it working proberbly since there is no 360 degree Raycast implemented.

avatar image Bunny83 · Mar 02, 2012 at 10:13 AM 0
Share

360° raycast? why? all you need to do is cast a raycast (or sphere cast) from the listener to every audiosource that should be "silenced" if not visible. If it's not visible, you can change the roll-off values so it's fading-out earlier.

avatar image hrlarsen · Mar 02, 2012 at 10:55 AM 0
Share

@Bunny83 How would you go about doing that? I can't seem to find a solution for casting rays to multiple objects

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Mar 02, 2012 at 12:46 PM

This is a theoretical solution. I haven't tested it yet and you have to play around with the distance values.

 // C#
 public class OccludableAudio : MonoBehaviour
 {
     private Transform m_MyTrans;
     private AudioSource m_Source;
     
     private float m_MaxDistance;
     
     public Transform Listener;
     public float OccludedDistance = 5.0f;
     public float FadeSpeed = 10.0f;
     public LayerMask Mask;
     
     void Start()
     {
         m_MyTrans = transform;
         m_Source = audio;
         m_MaxDistance = m_Source.maxDistance;
     }
     void Update()
     {
         float target;
         if (Physics.Linecast(Listener.position, m_MyTrans.position, Mask.value))
             target = OccludedDistance;
         else
             target = m_MaxDistance;
         m_Source.maxDistance = Mathf.MoveTowards(m_Source.maxDistance, m_Target, Time.deltaTime * FadeSpeed);
     }
 }

You have to attach this script to every audio source that should be able to be occluded. You have to assign your player to the Listener transform variable. Another way would be to make the Listener variable static and assign it from the player's script.

 public static Transform Listener;

 // In your players script:
 void Start()
 {
     //[...]
     OccludableAudio.Listener = transform;
 }

This way you only have to assign it once.

Don't forget to setup the layermask to specify what colliders should occlude the audio.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hrlarsen · Mar 02, 2012 at 01:57 PM 0
Share

Got it working with your solution thanks!

avatar image
0

Answer by DaveA · Mar 02, 2012 at 01:19 AM

You could set up some, say, Box colliders and use them as proximity detectors to tell the audio to attenuate accordingly. You'd want to change the volume the player hears rather than the source if it's multi-player (or at least, not propagate the volume to other players).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Mar 26, 2012 at 07:28 AM 0
Share

Work in progress: http://qlcomp.com/?page_id=20

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

3D Audio Source plays choppy/poping in web player (Video) 1 Answer

I need help about audio.PlayOneShot!! 1 Answer

how to fix 2d sound distortion? 1 Answer

Multiple audioSources on same gameObject? 1 Answer

help sound on collision when key down 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges