From bb95469f44012190d2104591dbdf0fe0ed1470db Mon Sep 17 00:00:00 2001 From: yuni Date: Sun, 17 Nov 2024 01:44:31 +0100 Subject: [PATCH] WIP crisper camera controls (fix slow acceleration (space+movement)) --- src/actor.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index a2feb67..1719fb1 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -842,8 +842,9 @@ fn handle_wants_acceleration( if accel.brake { if let Some(target_v) = closest_map.get(&entity) { let stop_direction = (*target_v - v.0).as_vec3(); - delta_v = (trans.rotation.inverse() * stop_direction).as_dvec3(); - if delta_v.length_squared() > 0.003 { + if stop_direction.length_squared() > 0.003 { + delta_v = + (trans.rotation.inverse() * stop_direction.normalize()).as_dvec3(); engine.currently_matching_velocity = true; thruster_on = true; } @@ -852,7 +853,8 @@ fn handle_wants_acceleration( if accel.direction != DVec3::ZERO { // Player is pressing AWSD keys - delta_v += accel.direction; + let brake_factor = if accel.brake { 1.10 } else { 1.0 }; + delta_v += accel.direction.normalize() * brake_factor; } else if accel.brake { // Player is only pressing space allow_fullstop = true; @@ -877,9 +879,10 @@ fn handle_wants_acceleration( * ENGINE_SPEED_FACTOR as f64 * engine.current_boost_factor; - let final_accel = - (trans.rotation * (delta_v.normalize() * engine_factor).as_vec3() * dt) - .as_dvec3(); + let final_accel = (trans.rotation + * (delta_v.clamp_length_max(1.0) * engine_factor).as_vec3() + * dt) + .as_dvec3(); // Apply acceleration to velocity if allow_fullstop { @@ -901,7 +904,7 @@ fn handle_wants_acceleration( // Visual effect if engine.engine_type == EngineType::Monopropellant { - let thruster_direction = delta_v.normalize(); + let thruster_direction = final_accel.normalize(); let thruster_pos = pos.0 - 0.3 * thruster_direction; let thruster_v = v.0 - boost * 5.0 * thruster_direction; ew_effect.send(visual::SpawnEffectEvent {