Skip to content

Commit

Permalink
Prevent NaN angle at zero emitter and receiver distance
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Dec 8, 2024
1 parent 1569135 commit 9537aeb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/spatial.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 9537aeb

Please sign in to comment.