File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -401,10 +401,19 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
401401 if (area && area->is_using_reverb_bus () && area->get_reverb_uniformity () > 0 ) {
402402 total_max = MAX (total_max, listener_area_pos.length ());
403403 }
404- if (total_max > max_distance) {
404+ if (dist > total_max || total_max > max_distance) {
405+ if (!was_further_than_max_distance_last_frame) {
406+ HashMap<StringName, Vector<AudioFrame>> bus_volumes;
407+ for (Ref<AudioStreamPlayback> &playback : internal->stream_playbacks ) {
408+ // So the player gets muted and mostly stops mixing when out of range.
409+ AudioServer::get_singleton ()->set_playback_bus_volumes_linear (playback, bus_volumes);
410+ }
411+ was_further_than_max_distance_last_frame = true ; // Cache so we don't set the volume over and over.
412+ }
405413 continue ; // can't hear this sound in this listener
406414 }
407415 }
416+ was_further_than_max_distance_last_frame = false ;
408417
409418 float multiplier = Math::db_to_linear (_get_attenuation_db (dist));
410419 if (max_distance > 0 ) {
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ class AudioStreamPlayer3D : public Node3D {
105105 float linear_attenuation = 0 ;
106106
107107 float max_distance = 0.0 ;
108+ bool was_further_than_max_distance_last_frame = false ;
108109
109110 Ref<VelocityTracker3D> velocity_tracker;
110111
You can’t perform that action at this time.
0 commit comments