Support pitch in footsteps.

This commit is contained in:
Nolan Darilek 2021-11-28 12:31:39 -06:00
parent e6fce1e28f
commit 07a4bd9d64

View File

@ -20,6 +20,7 @@ pub struct Footstep {
pub reference_distance: f32,
pub max_distance: f32,
pub rolloff_factor: f32,
pub pitch: f32,
pub pitch_variation: Option<f32>,
}
@ -32,6 +33,7 @@ impl Default for Footstep {
reference_distance: 1.,
max_distance: f32::MAX,
rolloff_factor: 1.,
pitch: 1.,
pitch_variation: Some(0.15),
}
}
@ -113,8 +115,9 @@ fn footstep(
sound.reference_distance = footstep.reference_distance;
sound.max_distance = footstep.max_distance;
sound.rolloff_factor = footstep.rolloff_factor;
sound.pitch = footstep.pitch;
if let Some(pitch_variation) = footstep.pitch_variation {
let mut pitch = 1. - pitch_variation / 2.;
let mut pitch = footstep.pitch - pitch_variation / 2.;
pitch += random::<f32>() * pitch_variation;
sound.pitch = pitch;
}