Third Person Listener with Wwise in Unity

    In first person games the listener’s panning and attenuation settings correspond to the position of the camera. The player sees and hears the world based on the player’s head and therefore camera position. In third person games the camera and the player’s position are detached from each other. In this case we usually want to pan the sounds in the world based on the camera position and rotation and attenuate based on the player’s position.

    Let’s create a new script named ThirdPersonListener.cs to set up this behaviour:

    using UnityEngine;
    using System;
    using System.Collections.Generic;
    
    [ExecuteInEditMode]
    public class ThirdPersonListener : AkGameObj
    {
        [SerializeField]
        private Transform player;          
    
        public override Vector3 GetPosition()
        {
            return player.GetComponent<AkGameObj>().GetPosition();
        }
    }

    If you already have an Ak Listener and an Ak Game Obj component attached to the camera, remove both. Attach the previously created script to the camera first:

    Third Person Listener script in Unity
    Third Person Listener script in Unity

    In the Player target field, insert the GameObject that will be used for updating the attenuation settings of the listener. It may be your player’s transform or another desired position. Now re-add the Ak Listener component to the camera GameObject. Make sure that the target GameObject has the Ak Game Obj component attached to it and you should be good to go. Start your scene and you will hear the camera affecting the panning of sounds while the attenuation is affected by the player’s position.

    ↑ To the Top