From b3885aa4b6adf1aaf64c5a12300b6aeb2239cbc3 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 29 Mar 2024 02:56:48 +0100 Subject: [PATCH] come to a full stop when braking while slow --- src/camera.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 76ad052..1ad754b 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -126,8 +126,20 @@ fn run_camera_controller( if axis_input.length_squared() > 0.003 { let acceleration_global = transform.rotation * (axis_input * factor); - actor.v += actor::ENGINE_SPEED_FACTOR * dt * acceleration_global; - + let mut acceleration_total = actor::ENGINE_SPEED_FACTOR * dt * acceleration_global; + let threshold = 1e-5; + if key_input.pressed(settings.key_stop) { + for i in 0..3 { + if actor.v[i].abs() < threshold { + actor.v[i] = 0.0; + } + else if (actor.v[i] < 0.0 && actor.v[i] + acceleration_total[i] > 0.0) || (actor.v[i] > 0.0 && actor.v[i] + acceleration_total[i] < 0.0) { + actor.v[i] = 0.0; + acceleration_total[i] = 0.0; + } + } + } + actor.v += acceleration_total; engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); play_thruster_sound = !settings.mute_sfx; }