Search Unity

Applying a Reverb Filter to a collision event

Discussion in 'Audio & Video' started by Explorer1, Aug 31, 2015.

  1. Explorer1

    Explorer1

    Joined:
    Feb 5, 2013
    Posts:
    11
    I am working on a game where the player is able to fire a red cube prefab at a wall and when that happens, reverb is applied depending on the Reverb Filter attached to the wall. The end goal is that the walls are the sides of a large verticle tunnel and depending how deep they are, the reverb is adjusted accordingly. I can't use Reverb Zones because the player is not able to go down the vertical tunnel.

    The wall is a primited 3D cube flattened out. The shooting and audio triggering element is working perfectly and I have attached a script to the prefab that allows me to add multiple impact sounds to it. I am using a collision event to detect when prefab hits the wall and then I trigger these sounds in 3D space using PlayOneShot. Here is the script attached to the Prefab:

    Code (csharp):
    1. usingUnityEngine;
    2. usingSystem.Collections;
    3.  
    4. [RequireComponent(typeof(AudioSource))]
    5. public class crateCol : MonoBehaviour {
    6.  
    7.     public AudioClip[] collisionClips;
    8.     public float impactToVolRatio = .2F;
    9.     public float minCollisionVolume = .1F;
    10.     public int _nextClipIndex = 0;
    11.  
    12.     void OnCollisionEnter ( Collision coll ) {
    13.         float volume = coll.relativeVelocity.magnitude * impactToVolRatio;
    14.         volume = Mathf.Clamp ( volume, minCollisionVolume, 1f );
    15.         GetComponent<AudioSource().PlayOneShot ( collisionClips[_nextClipIndex], volume );
    16.         _nextClipIndex = ( _nextClipIndex + 1 ) % collisionClips.Length;
    17.  
    18.     }
    19.  
    20. }
    I tried adding the Reverb Filter to the prefab but when the audio is triggered multiple times on a wall surface it resets the reverb such as demonstrated in this video:


    If I attach the reverb filter to the wall, it requires an audio clip which is on the prefab. I need to grab the clip that is played on collision and send it to the reverb filter.
    Is this the right way of doing it?

    Any help much appreciated!