0
\$\begingroup\$

Is there a way to make a reverb zone act on an audio source not on the audio listener? Or in other words: Is there a way to apply an audio filter gradually depending on a position in space?

Let's say I have three objects: A plane with a reverb zone attached (some echo-effect), a movable sphere with an audio source and a player character with an audio listener. If I use the player character to push the sphere onto the plane the audio will be echoed, but as soon as the player leaves the plane the audio loses it's effect, because the listener left the zone. Is there any way to make the zone act on the source, not the listener?

\$\endgroup\$
  • \$\begingroup\$ Have you considered using an Audio Mixer group for this? \$\endgroup\$ – DMGregory May 20 at 11:37
  • \$\begingroup\$ Awesome, this works great! Thanks for pointing in the right direction! \$\endgroup\$ – Jacques Knie May 31 at 14:41
  • \$\begingroup\$ If you've solved your problem, please consider posting it as an answer to help other users working on similar topics. \$\endgroup\$ – DMGregory May 31 at 14:45
0
\$\begingroup\$

My solution looks like this. I created an audiomixer with the effects that I want to apply and some 3D-shape as trigger (a cube for example). To this trigger I add the following script, which allows to attach the audiomixer to the trigger. As soon as any object with an audio-source component enters the trigger the audio of the object will be fed into the audiomixer.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class AddAudioMixer : MonoBehaviour
{

    public AudioMixerGroup audioMixer;


    void OnTriggerEnter (Collider other)
    {
        if (other.gameObject.GetComponent<AudioSource>() != null){
            AudioSource compAudio;
            compAudio = other.gameObject.GetComponent<AudioSource>();
            compAudio.outputAudioMixerGroup = audioMixer;
        } else {
            Debug.Log("No Audiosource on this Component");
        }
    }

    void OnTriggerExit (Collider other)
    {
        if (other.gameObject.GetComponent<AudioSource>() != null){
            AudioSource compAudio;
            compAudio = other.gameObject.GetComponent<AudioSource>();
            compAudio.outputAudioMixerGroup = null;
        } else {
            Debug.Log("No Audiosource on this Component");
        }
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.