• 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 Robidoo · Mar 04, 2014 at 09:51 PM · soundfilter

I'm using the echo filter but it appears to work only when my object isn't moving.

This is the where the echo filter is affected. This script is attached to a car. The effects works fine when the car is not moving but the sound doesn't get the echo while moving. The reverb filter works fine when it should.

 void Update () {
     float echoValue = 0.0f;
     float delayValue = 0.0f;
     int counter = 0;

     var lft = transform.TransformDirection (Vector3.left);
     var rght = transform.TransformDirection (Vector3.right);
     var up = transform.TransformDirection (Vector3.up);
     var frnt = transform.TransformDirection (Vector3.forward);
     var bck = transform.TransformDirection (Vector3.back);

     Physics.Raycast (transform.position + addLft, lft, out hl, 40);
     Physics.Raycast (transform.position + addRght, rght, out hr, 40);
     Physics.Raycast (transform.position + addUp, up, out hu, 40);
     Physics.Raycast (transform.position + addBck, bck, out hb, 40);
     Physics.Raycast (transform.position + addFrnt, frnt, out hf, 40);

     if(IsColliding(hf)){
             angle = Vector3.Angle(frnt,hf.normal) - 90.0f;
             angle = angle / 100;
             if(angle < 0.25f){
                 angle = angle / 4;
             }
             else if (angle < 0.5f){
                 angle = angle / 2;
             }
             echoValue = echoValue + (angle/3);
             
             delayValue = delayValue + ((hf.distance*2.0f)/342.0f)*1000.0f;
             counter++;
     }

     if(IsColliding(hb)){
             angle = Vector3.Angle(bck,hb.normal) - 90.0f;
             angle = angle / 100;
             if(angle < 0.25f){
                 angle = angle / 4;
             }
             else if (angle < 0.5f){
                 angle = angle / 2;
             }
             echoValue = echoValue + (angle/3);

         delayValue = delayValue + ((hb.distance*2.0f)/342.0f)*1000.0f;
         counter++;
     }

     if(IsColliding(hl)){
             angle = Vector3.Angle(lft,hl.normal) - 90.0f;
             angle = angle / 100;
             if(angle < 0.25f){
                 angle = angle / 4;
             }
             else if (angle < 0.5f){
                 angle = angle / 2;
             }
             echoValue = echoValue + (angle/3);

         delayValue = delayValue + ((hl.distance*2.0f)/342.0f)*1000.0f;
         counter++;
     }

     if(IsColliding(hr)){
             angle = Vector3.Angle(rght,hr.normal) - 90.0f;
             angle = angle / 100;
             if(angle < 0.25f){
                 angle = angle / 4;
             }
             else if (angle < 0.5f){
                 angle = angle / 2;
             }
             echoValue = echoValue + (angle/3);

         delayValue = delayValue + ((hr.distance*2.0f)/342.0f)*1000.0f;
         counter++;
     }

     if(IsColliding(hu)){
             angle = Vector3.Angle(up,hu.normal) - 90.0f;
             angle = angle / 100;
             if(angle < 0.25f){
                 angle = angle / 4;
             }
             else if (angle < 0.5f){
                 angle = angle / 2;
             }
             echoValue = echoValue + (angle/3);

         delayValue = delayValue + ((hu.distance*2.0f)/342.0f)*1000.0f;
         counter++;
     }

     _echo.wetMix = echoValue;

     if(counter > 0){
         delayValue = delayValue/counter;
         if(delayValue < 80.0f){
             if(counter > 2){
                 _rev.reverbPreset = AudioReverbPreset.Alley;
                 _echo.wetMix = 0.0f;
             }
         }else{
             _echo.delay = (delayValue);
             _rev.reverbPreset = AudioReverbPreset.Off;
         }
     }else{
         _rev.reverbPreset = AudioReverbPreset.Off;
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

OnAudioFilterRead issues on Android? 1 Answer

How to make my machinegun echo? 3 Answers

cannot find any information on how to use custom filters / real time sound generation in 3.5 2 Answers

Procedural native audio synthesis with OnAudioFilterRead 1 Answer

Generating an Echo effect in Unity 3 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