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
3
Question by Uriel_96 · Feb 11, 2011 at 11:58 PM · javascriptenemysounddetection

Enemy sound detection

OK, In my game that is a FPS style game, Im trying to do a sound detection, and for this I have many ideas but I actually don't know how to make that in a script so first I want like a combination of sounds that it actually depends on the volume of the sound, the distance between the enemy and the sound and stop where is a obstacle(something like this). And for last I want something like detection with reverb zone so like that it will depend on how far does the sound was to the enemy.

Note: I am using JavaScript and if the answer is a code it would be better :).

Please if someone knows something about this please answer and if you have questions of this question please comment.

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

5 Replies

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

Answer by Soby · Feb 12, 2011 at 01:48 AM

This is actually kinda funny to see posted cuz im going to be working on a solution to this tomarrow.. their's 2 ways Im going to be lookin into.. which ever one works first I'll use or if none work I'll go back to the drawing board... Though the raycasting thing seems like one of the easier ways but Im curious because racast is only in one direction no? so if your not facing the enemy how will that help? or are you talking about doing a spherecast?

the 2 ideas Im going to be trying are:

  1. there's suposedly seperate listeners for this type of situation that can be placed on enemies and depending on how far away you are you can set up the roll off and such to get the distances you want for multiple detections... for me we need it for stealthing around and making sure the enemy can still see you if your right infront of them but muffle the noise in stealth mode so they can only really hear you if your runing, walking, jumping...

  2. My idea is not fully looked into but I seen somewhere you can actually access a calculated distance between objects, from what I gathered it didnt mention a raycast of any sort but I would imagine it would need one. But simular to the above, just use a variable named distance which is Distance and its suposed to calculate distances to what ever you assign it to. Again this isnt fully looked into so there's alot of gaps in it atm.

if I do happen to get it to work tho, I'll be sure to post it here... I too am using JS.

Comment
Add comment · Show 3 · 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 Uriel_96 · Feb 12, 2011 at 02:11 AM 0
Share

thanks, I will be waiting for it to work :)

avatar image celadon · Feb 12, 2011 at 07:07 AM 2
Share
  1. From the manual: Each scene can only have one Audio Listener. The Audio Listener is for the player (the user interface), not for the objects in your game world.

  2. You can use Vector3.Distance(position1, position2) to get the distance between two objects

I think your steps would be: a. use Physics.CheckSphere (not a spherecast) to find all of the colliders in a given radius around the character b. identify the ones you care about (e.g. enemy) and use the Vector3.Distance to find out how close they are c. then do the raycast between those two objects to check for a wall or whatever.

avatar image Soby · Feb 12, 2011 at 07:19 AM 0
Share

Thats what I originally thought with the audio listener bc thats what i read as well. However someone else mentioned there is a different type of listener for this kind of situation. Im not entirely sure if its possible or true but I plan on lookin into it since it came from my lead. However the way you stated is the way i was reffering to and it was my first idea. Which thus far my 1st idea usually work out the best. :)

avatar image
1
Best Answer

Answer by Soby · Feb 14, 2011 at 02:09 AM

Put this on the enemy but you will need to alter it based on your needs. This is set up for seathling and such... this doesnt take into consideration of walls but you can do a simple raycast or simplly dont put them close to a wall lol

the formatting on here got all wacky so i posted it on one of my blogs the link is below:

Enemy Detection

you will need to reformat the script... didn't c/p the way i had it originally.

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

Answer by kennypu · Feb 12, 2011 at 12:26 AM

instead of actually trying to detect a "sound", you can just set a variable that stores like a noiseLevel, and if the distance from the player to the enemy is smaller than the noiseLevel, the enemy knows you're there.

for example, when you're not doing anything, the noise level is 0. when you're walking it is 1. if you shoot, it is 10. and if the distance from the enemy to you is smaller than the noiselevel, they find you.

Comment
Add comment · Show 2 · 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 Uriel_96 · Feb 12, 2011 at 12:42 AM 0
Share

yeah that sounds a good idea, but I also considering to make an stop sound, that $$anonymous$$es that if there is a wall between enemy and sound there would be not detection or less detection that if there is not a wall, but thanks any way, I never got an idea like that:P

avatar image kennypu · Feb 12, 2011 at 01:13 AM 0
Share

well you can raycast from the player(or sound source) to the enemy, and if there is a wall in between, you can reduce the noiseLevel variable, thus weakening the sound.

avatar image
1

Answer by DaveA · Feb 12, 2011 at 01:13 AM

As kennypu said, but you could also cast a ray between the player and the sound and 'attenuate' based on what it hits in between. Not exact, but could be close enough.

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

Answer by celadon · Feb 12, 2011 at 01:19 AM

I also briefly wondered about this, but quickly rejected it as totally infeasible - it would need to be modeled by the physics engine, and you would not only need to model all of the audio sources, and the audio listener, but every material would have to be given values for how reflective and/or absorptive it is... way too much computation.

You could always do a raycast between the sound source (e.g. character) and the "listener" (e.g. enemy) and try and detect any sound barriers between them. If found, you could adjust the sound level/distance calculation. (You would have to decide how to detect the sound barriers and what kind of adjustment to make).

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

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

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Finding Positions of other game objects and using them as an argument for an if statement. 0 Answers

AI wandering script needs help. 0 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