From 9c2b2e4e0f3500d550c20fbdecc41fb6033e0ce2 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 17 Mar 2024 14:39:42 +0100 Subject: [PATCH] add Space key to slow down --- src/camera.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 7224447..bea8a90 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -29,6 +29,7 @@ pub struct CameraController { pub key_up: KeyCode, pub key_down: KeyCode, pub key_run: KeyCode, + pub key_stop: KeyCode, pub mouse_key_cursor_grab: MouseButton, pub keyboard_key_toggle_cursor_grab: KeyCode, pub move_speed: f32, @@ -51,10 +52,11 @@ impl Default for CameraController { key_up: KeyCode::ShiftLeft, key_down: KeyCode::ControlLeft, key_run: KeyCode::KeyR, + key_stop: KeyCode::Space, mouse_key_cursor_grab: MouseButton::Left, keyboard_key_toggle_cursor_grab: KeyCode::KeyM, move_speed: 1.0, - friction: 0.0, + friction: 0.1, pitch: 0.0, yaw: 0.0, velocity: Vec3::ZERO, @@ -157,13 +159,18 @@ fn run_camera_controller( } let cursor_grab = *mouse_cursor_grab || *toggle_cursor_grab; + let friction = if key_input.pressed(controller.key_stop) { + controller.friction.clamp(0.0, 1.0) + } else { + 0.0 + }; + // Apply movement update if axis_input != Vec3::ZERO { let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed; controller.velocity = new_velocity; play_thruster_sound = true; } else { - let friction = controller.friction.clamp(0.0, 1.0); controller.velocity *= 1.0 - friction; if controller.velocity.length_squared() < 1e-6 { controller.velocity = Vec3::ZERO;