Audio Ears on the Character, not the Camera?

There is a much easier and more organic way to achieve this without doing anything on tick or hacking together rotations, for future googlers (I know, its an old thread). Override APlayerController::GetAudioListenerPosition() and add:


if (GetPawn())
{
    ViewLocation = GetPawn()->GetActorLocation();
}

In the else statement under GetPlayerViewPoint(ViewLocation, ViewRotation), here’s the full function. The result is that it uses the pawn’s location but the camera’s rotation.


FVector ViewLocation;
FRotator ViewRotation;

if (bOverrideAudioListener)
{
    USceneComponent* ListenerComponent = AudioListenerComponent.Get();
    if (ListenerComponent != nullptr)
    {
        ViewRotation = ListenerComponent->GetComponentRotation() + AudioListenerRotationOverride;
        ViewLocation = ListenerComponent->GetComponentLocation() + ViewRotation.RotateVector(AudioListenerLocationOverride);
    }
    else
    {
        ViewLocation = AudioListenerLocationOverride;
        ViewRotation = AudioListenerRotationOverride;
    }
}
else
{
    GetPlayerViewPoint(ViewLocation, ViewRotation);
    if (GetPawn())
    {
        ViewLocation = GetPawn()->GetActorLocation();
    }
}

const FRotationTranslationMatrix ViewRotationMatrix(ViewRotation, ViewLocation);

OutLocation = ViewLocation;
OutFrontDir = ViewRotationMatrix.GetUnitAxis(EAxis::X);
OutRightDir = ViewRotationMatrix.GetUnitAxis(EAxis::Y);

5 Likes