When you create a 3rd person game in UE4, the Audio Listener is set by default to the position of the camera, which works fine for some scenarios but not for others. It can cause problems depending on the position of the camera relative to the player character (eg. hearing things that the character cannot actually see).
I was asked about this by one of our Masters students who needed to be able to set the position of the Audio Listener to somewhere in-between the camera and the player character in order to solve just this kind of problem.
This is my solution – it does not need to be in a separate BP, but by doing so it makes it easy to distribute and means it can simply by dropped into a project.
Within the BP, the Audio Listener is set to the position of the actor, which in turn has it’s position constantly updated so that it is always relative to both the player character and the player camera.
On every frame update the location of the player camera and character are obtained as well as the forward vector of the camera and it’s rotation. These positions are used to calculate the position of the actor.
The forward vector of the camera tells us the direction the camera is facing.
The distance between the player camera and the character is obtained and is scaled by a user-definable variable to determine how far along a line between the camera and character the actor should be placed.
This value is then used to scale the forward vector of the camera to move the actor along the axis of the camera towards the player character.
Finally I added in a [VInterp To] node to apply some level of interpolation on the actor’s location so that there is some degree of ‘inertia’ on the listener position’s movements – this smooths out any jumpy movements introduced by the camera.
The actor’s properties allow you to set:
– The Listener Distance (where 0 = at the position of the player character, and 1 = at the position of the player camera)
– The Interp Speed (where 100 = very fast movement / no inertia, and 1 = very slow movement / high degree of inertia)
You can toggle the actor’s Hidden in Game state using the L key (obviously you can change this key event if you wish) so that you can visualize the listener position if needs be.
The actor can be downloaded from here: click me
If you find this useful and have any thoughts / suggestions / ideas for developing it further so that it can be of more use, I’d be interesting in hearing from you…