From 9537aeb54a98d6bb04f7fa743aee7807f4ca3ccf Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Sun, 8 Dec 2024 16:42:52 +0100 Subject: [PATCH 1/2] Prevent NaN angle at zero emitter and receiver distance --- src/spatial.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/spatial.rs b/src/spatial.rs index a5d586b..6aa9c67 100644 --- a/src/spatial.rs +++ b/src/spatial.rs @@ -1,7 +1,9 @@ use crate::{AudioInstance, AudioTween}; use bevy::asset::{Assets, Handle}; use bevy::ecs::component::Component; +use bevy::math::Vec3; use bevy::prelude::{GlobalTransform, Query, Res, ResMut, Resource, With}; +use std::f32::consts::PI; /// Component for audio emitters /// @@ -45,7 +47,11 @@ impl SpatialAudio { .clamp(0., 1.) .powi(2); - let right_ear_angle = receiver_transform.right().angle_between(sound_path); + let right_ear_angle = if sound_path == Vec3::ZERO { + PI / 2. + } else { + receiver_transform.right().angle_between(sound_path) + }; let panning = (right_ear_angle.cos() + 1.) / 2.; for instance in emitter.instances.iter() { From e74796da585bf515e7fdf428bb8c119ce601619f Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Sun, 8 Dec 2024 16:44:41 +0100 Subject: [PATCH 2/2] Update changelog with spatial fix --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c8461..c55cbe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +- fix spatial audio when position of receiver and emitter are the same ([#135](https://github.com/NiklasEi/bevy_kira_audio/issues/135)) + ## v0.21.0 - 30.11.2024 - Update to Bevy `0.15`