Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Skeletim · Jul 15, 2013 at 03:27 AM · collidertriggeraudio sourceontrigger

Player position within audio source range

I'm trying to come up with a way to determine if the player is within the range of an audio source, and I'm having trouble figuring out way to do it. I've looked through various answers, forum posts, and scripting reference materials. I've experimented with using triggers or collisions within the source, and just make a sphere collider the same size of the range. It's not any particular audio source though, but all of them. I need to find a way to check if the player is within any particular audio source in general, and if they are within range then the can do x, else y happens.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Benproductions1 · Jul 15, 2013 at 03:35 AM

Hello,

AudioSources do not have a range. The volume of the sound that comes out of Unity is determined by a fall off. This fall off is determined per AudioSource in the "3d Sound Settings".
The default falloff settings are logarithmic and determined by a pre-defined curve. As of now, there is no direct way of accessing that curve to find the volume based on distance.

However there are two things you can do: 1. Use the "MaxDistance" and apply your own falloff to mathematically determine the volume at any given point. 2. Determine the "volume" at the point of the AudioListener by analysing the output sound data.

Neither of the ways are nice (or easy if you don't know how), but they do work :)

Hope this helps,
Benproductions1

Comment
Add comment · Show 5 · 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 Skeletim · Jul 15, 2013 at 01:07 PM 1
Share

I wouldn't really need to know volume, just to know if player was within $$anonymous$$axDistance. But, if thats the case, it seems like an on trigger collider would be the best bet, or easiest. So essentially, I would add a collider to every sound source, and add an OnTriggerStay script to the player to check if when he enters a trigger collider that is a component of an audiosource then do stuff. Would that be the way to do it then?

avatar image Benproductions1 · Jul 15, 2013 at 10:22 PM 0
Share

The question is: At what point does the volume fall off to 0. I highly suggest against using triggers. They generate an unessecarily large overhead. Just "Find" all audio sources and calculate the distance. If that distance is smaller than something, your character can hear it.

avatar image Skeletim · Jul 16, 2013 at 06:53 PM 0
Share

How is the overhead on that compared to triggers? That was one of the things I was afraid of in doing that, because I would have to do a search for ALL audio sources on a map. For the concept I'm going for, the $$anonymous$$Distance would be 10, for example, and the maxDistance would be 10.1 (since I can't have them both 10.

I guess the way I said "add a collider to ever sound source" was a bit misleading now that I look at it. In my case, I may many audio sources in a scene, but only maybe 6 or so would be ones that need the player to respond to. I can tag them 'special' or something, and do a search for audio sources with tags of 'special' and see if I'm within x distance to them, or add a trigger to each of the 6 and check player collides with it.

So comparing those two methods, which is more efficient? It seemed unnecessary to search for audio during every frame as the player moves through a scene.

avatar image Benproductions1 · Jul 17, 2013 at 02:13 AM 0
Share

There is no overhead. Just "Find" all your audio sources when the scene loads, "cache" them and then check the distance. $$anonymous$$y method checks for distance, while yours checks for collision. $$anonymous$$ine will always be faster (as long as you cache your audio sources)

Your method also means, that if you want to use triggers for anything else, you will have to add exceptions for colliding with certain people.

avatar image Skeletim · Jul 17, 2013 at 03:02 AM 0
Share

I'll see if I can change my script to do that.

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

16 People are following this question.

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

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Problem with the collider(I think) 0 Answers

How having correct bounce on a rotating pinwheel(it's more complicated)? 0 Answers

Enable objects to enter the trigger 2 Answers

Climbing using OnTriggerEnter and Arrow Keys? 1 Answer


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