From 8f682ee5b631d5c14ac1d32a9038478d0726f2ae Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 29 Mar 2024 02:40:55 +0100 Subject: [PATCH] cleanup --- src/actor.rs | 1 + src/camera.rs | 36 +++++++++--------------------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 36c51e2..bd76880 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -1,6 +1,7 @@ use bevy::prelude::*; use crate::{nature, settings, actor, audio, hud}; +pub const ENGINE_SPEED_FACTOR: f32 = 30.0; const MIN_INTERACT_DISTANCE: f32 = 30.0; const NO_RIDE: u32 = 0; diff --git a/src/camera.rs b/src/camera.rs index cf13cf0..ab204c5 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -98,32 +98,18 @@ fn run_camera_controller( if key_input.pressed(settings.key_down) { axis_input.y -= 1.0; } - } - - if key_input.pressed(settings.key_stop) { - if actor.v.length_squared() < 1e-6 { - actor.v = Vec3::ZERO; + if key_input.pressed(settings.key_stop) { + let stop_direction = -actor.v.normalize(); + if stop_direction.length_squared() > 0.3 { + axis_input += 0.7 * (transform.rotation.inverse() * stop_direction); + } } } let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine }; // Apply movement update - let mut acceleration_camera: Vec3; - if axis_input != Vec3::ZERO { - acceleration_camera = axis_input; - } else { - acceleration_camera = Vec3::ZERO; - } - - 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 { + let forward_factor = engine.current_warmup * (if axis_input.z < 0.0 { engine.thrust_forward } else { engine.thrust_back @@ -132,13 +118,9 @@ fn run_camera_controller( let up_factor = engine.thrust_sideways * engine.current_warmup; let factor = Vec3::new(right_factor, up_factor, forward_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; + if axis_input.length_squared() > 0.003 { + let acceleration_global = transform.rotation * (axis_input.normalize() * factor); + actor.v += actor::ENGINE_SPEED_FACTOR * dt * acceleration_global; engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); play_thruster_sound = !settings.mute_sfx;