From ac747ac9c3d60569c9ab92090d0e2f04c08c2f36 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 29 Mar 2024 02:21:28 +0100 Subject: [PATCH] stop key now breaks with proper engine physics --- src/camera.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 3a82b8e..cf13cf0 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -109,17 +109,21 @@ fn run_camera_controller( let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine }; // Apply movement update - let acceleration_camera: Vec3; + let mut acceleration_camera: Vec3; if axis_input != Vec3::ZERO { - acceleration_camera = axis_input.normalize(); - engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); - play_thruster_sound = !settings.mute_sfx; + acceleration_camera = axis_input; } else { acceleration_camera = Vec3::ZERO; - engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); } - let forward_factor = engine.current_warmup * (if axis_input.z < 0.0 { + if key_input.pressed(settings.key_stop) { + let stop_direction = -actor.v.normalize(); + if stop_direction.length_squared() > 0.3 { + acceleration_camera += transform.rotation.inverse() * stop_direction; + } + } + + let forward_factor = engine.current_warmup * (if acceleration_camera.z < 0.0 { engine.thrust_forward } else { engine.thrust_back @@ -128,10 +132,20 @@ fn run_camera_controller( let up_factor = engine.thrust_sideways * engine.current_warmup; let factor = Vec3::new(right_factor, up_factor, forward_factor); - let acceleration_global = transform.rotation * (acceleration_camera * factor); + if acceleration_camera.length_squared() > 0.3 { + let acceleration_global = transform.rotation * (acceleration_camera.normalize() * factor); + dbg!(acceleration_camera); + dbg!(acceleration_global); - let speed_multiplier = 30.0; - actor.v += speed_multiplier * dt * acceleration_global; + let speed_multiplier = 30.0; + actor.v += speed_multiplier * dt * acceleration_global; + + engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); + play_thruster_sound = !settings.mute_sfx; + } + else { + engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); + } // Handle mouse input let mut mouse_delta = Vec2::ZERO;