better reaction wheel sound

This commit is contained in:
yuni 2024-03-31 05:13:13 +02:00
parent 61e02ed6ca
commit 852dd79657

View file

@ -256,8 +256,7 @@ fn apply_input_to_player(
angularvelocity.0 *= angular_slowdown.clamp(0.97, 1.0); angularvelocity.0 *= angular_slowdown.clamp(0.97, 1.0);
} }
else { else {
if angularvelocity.length_squared() > 0.0000001 { if angularvelocity.length_squared() > 0.001 {
play_reactionwheel_sound = true;
angularvelocity.0 *= angular_slowdown; angularvelocity.0 *= angular_slowdown;
} }
else { else {
@ -268,20 +267,18 @@ fn apply_input_to_player(
// Play sound effects // Play sound effects
if let Ok(sink) = electricmotor_sound_controller.get_single() { if let Ok(sink) = electricmotor_sound_controller.get_single() {
let volume = sink.volume(); let volume = sink.volume();
let max = (pitch_yaw_rot.length() * 10.0).clamp(0.2, 1.0); let speed = sink.speed();
let max_speed = 1.0; let action = pitch_yaw_rot.length_squared().powf(0.2) * 0.0005;
let rise = 0.07;
let fall = 0.15;
if play_reactionwheel_sound { if play_reactionwheel_sound {
sink.set_volume((volume + rise).clamp(0.0, max)); sink.set_volume((volume + action).clamp(0.0, 1.0));
sink.set_speed((volume + rise).clamp(0.2, max * max_speed)); sink.set_speed((speed + action * 0.2).clamp(0.2, 0.5));
sink.play() sink.play()
} else { } else {
if volume <= 0.01 { if volume <= 0.01 {
sink.pause() sink.pause()
} else { } else {
sink.set_volume((volume - fall).clamp(0.0, max)); sink.set_volume((volume - 0.01).clamp(0.0, 1.0));
sink.set_speed((volume - fall).clamp(0.2, max * max_speed)); sink.set_speed((speed - 0.03).clamp(0.2, 0.5));
} }
} }
} }