Hi, recently I wanted to add a simple audio occlusion effect to my project. After quick google, I found the “set3DOcclusion” function that I can call on my ChannelGroup. The problem is that the function does nothing where stuff like “setVolume” does.
When debugging, I tried getting the information through “get3DOcclusion” and I was confused as it returns 0 (even though I set it to 1).
public class FirstPersonOcclusion : MonoBehaviour
{
[S] EventReference eventReference;
[S] EventInstance Audio;
[S] EventDescription AudioDes;
[S] StudioListener Listener;
[S] PLAYBACK_STATE pb;
[S] LayerMask OcclusionLayer;
[S] bool AudioIsVirtual;
[S] float MinDistance;
[S] float MaxDistance;
[S] float ListenerDistance;
[S] Color colour;
ChannelGroup group;
float a;
float b;
private void Start()
{
Audio = RuntimeManager.CreateInstance(eventReference);
RuntimeManager.AttachInstanceToGameObject(Audio, GetComponent<Transform>(), GetComponent<Rigidbody>());
Audio.start();
AudioDes = RuntimeManager.GetEventDescription(eventReference);
AudioDes.getMinMaxDistance(out MinDistance, out MaxDistance);
Listener = FindObjectOfType<StudioListener>();
}
private void Update()
{
Audio.isVirtual(out AudioIsVirtual);
Audio.getPlaybackState(out pb);
ListenerDistance = Vector3.Distance(transform.position, Listener.transform.position);
if (!AudioIsVirtual && pb == PLAYBACK_STATE.PLAYING && ListenerDistance <= MaxDistance)
{
@group.set3DOcclusion(1f, 1f);
@group.get3DOcclusion(out a, out b);
Debug.Log(a + " "+ b);
}
}
I also fiddled around with the initialization flags like “FMOD_INIT_CHANNEL_LOWPASS” but that didn’t help either.
How exactly does the function work and how to use it?