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
1
Question by uskak41kw · Dec 15, 2013 at 12:29 AM · raycastplayerenemysound

can foe hear us?

I need some way to detect, can enemy character hear our player. I can check distance betwen player and foe, i can cast ray to check obstacle. But i dont know how to solve "corner" problem. Foe can hear me really good if he stays next to the corner, but raycast will say there is obstacle. Is there any way to work with real sound in U3d?alt text

corner.jpg (28.3 kB)
Comment
Add comment · Show 2
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 robertbu · Dec 15, 2013 at 01:26 AM 1
Share

Here is a possibility that is not perfect but may move you in the right direction. Raycast both from the Foe to the Player and from the Player to the Foo. Find the distance between the two hit points. Scale the distance the player can hear by the some factor based on the distance calculated. The larger the obstruction, the shorter the distance the player can hear.

avatar image LukaKotar · Dec 15, 2013 at 01:29 AM 0
Share

Unity free or Unity pro?

1 Reply

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

Answer by YoungDeveloper · Dec 15, 2013 at 02:08 AM

The player itself should cast spherical trigger around it, it's size based on is the player running or walking speed/ loudness.

I think this is the rare time "sendmessage" is usable, or you could call a method by comparing tags. But sendmessage might be better because there can be many enemy's.

When player moves and casts invisible sphere around him, you can get all gameobjects in that certain area, then run a tag search loop checking which GO are "Enemy", then call a method or sendmessage to those gameobjects with coordinates where the sound came from, so instead of Foe automatically following the player, it will go where the sound was, which is realistic.

alt text

This is how it could look like. For calling a methods, that is located on "Foe", you will need to getComponent and etc, so sendmessage might be a good idea as i said.

https://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessage.html

For sphere cast https://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html Basically you will have an array of all colliders inside that sphere, so from here can find anything, is it a foe, etc.

But as sendmassage takes only one parameter, i don't if that is possible, but you could send a class object, which contains those two coordinates.

Here's an interesting video, how it may look. http://youtu.be/Egy40TYFut8?t=55s


2076572d677cff0af66838030a7c348a.png (8.8 kB)
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 uskak41kw · Dec 15, 2013 at 02:50 AM 0
Share

God idea, but we still have a problem, it solve "corner" problem but if there a wall? Foe can't hear us.

avatar image YoungDeveloper · Dec 15, 2013 at 02:58 AM 0
Share

You could hear someone behind the wall actually, i think more what you mean if the wall is long, because there can also be short wall, which ends near by.

The solution on this, could be calculation the path distance using path finding grid. If the distance is long, don't go, if its short go.

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

18 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 avatar image avatar image

Related Questions

Enemy raycast chase player 0 Answers

enemy detect player then attack - c# 1 Answer

Play sound only once. 1 Answer

How can I check the line of sight to see if the player is visible to the enemy? 1 Answer

play sound after destroy the enemy by tag 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