From 20ceba9e820695aed4491b732ac743f3b92f93bf Mon Sep 17 00:00:00 2001 From: Uxeron Date: Tue, 22 Nov 2022 22:37:38 +0200 Subject: [PATCH] Fix AudioListener2D ignoring rotation --- scene/2d/audio_stream_player_2d.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 9ac3083718d..d5074f99714 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -174,13 +174,14 @@ void AudioStreamPlayer2D::_update_panning() { //screen in global is used for attenuation AudioListener2D *listener = vp->get_audio_listener_2d(); + Transform2D full_canvas_transform = vp->get_global_canvas_transform() * vp->get_canvas_transform(); if (listener) { listener_in_global = listener->get_global_position(); - relative_to_listener = global_pos - listener_in_global; + relative_to_listener = (global_pos - listener_in_global).rotated(-listener->get_global_rotation()); + relative_to_listener *= full_canvas_transform.get_scale(); // Default listener scales with canvas size, do the same here. } else { - Transform2D to_listener = vp->get_global_canvas_transform() * vp->get_canvas_transform(); - listener_in_global = to_listener.affine_inverse().xform(screen_size * 0.5); - relative_to_listener = to_listener.xform(global_pos) - screen_size * 0.5; + listener_in_global = full_canvas_transform.affine_inverse().xform(screen_size * 0.5); + relative_to_listener = full_canvas_transform.xform(global_pos) - screen_size * 0.5; } float dist = global_pos.distance_to(listener_in_global); // Distance to listener, or screen if none.