This commit is contained in:
yuni 2024-03-29 01:13:28 +01:00
parent 73d96aa69c
commit 33bb26b8e1

View file

@ -26,7 +26,6 @@ pub struct CameraController {
pub friction: f32, pub friction: f32,
pub pitch: f32, pub pitch: f32,
pub yaw: f32, pub yaw: f32,
pub velocity: Vec3,
} }
impl Default for CameraController { impl Default for CameraController {
@ -39,7 +38,6 @@ impl Default for CameraController {
friction: 0.05, friction: 0.05,
pitch: 1.0, // pitch=0/yaw=0 -> face sun pitch: 1.0, // pitch=0/yaw=0 -> face sun
yaw: 0.3, yaw: 0.3,
velocity: Vec3::ZERO,
} }
} }
} }
@ -112,26 +110,18 @@ fn run_camera_controller(
actor.v = Vec3::ZERO; actor.v = Vec3::ZERO;
} }
} }
let friction = if key_input.pressed(settings.key_stop) {
controller.friction.clamp(0.0, 1.0)
} else {
0.0
};
let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine }; let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine };
// Apply movement update // Apply movement update
let acceleration: Vec3;
if axis_input != Vec3::ZERO { if axis_input != Vec3::ZERO {
let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed; acceleration = axis_input.normalize() * controller.move_speed;
controller.velocity = new_velocity;
engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0);
play_thruster_sound = !settings.mute_sfx; play_thruster_sound = !settings.mute_sfx;
} else { } else {
controller.velocity *= 1.0 - friction; acceleration = Vec3::ZERO;
engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0);
if controller.velocity.length_squared() < 1e-6 {
controller.velocity = Vec3::ZERO;
}
} }
let forward = *transform.forward() * engine.current_warmup * (if axis_input.z > 0.0 { let forward = *transform.forward() * engine.current_warmup * (if axis_input.z > 0.0 {
@ -141,11 +131,9 @@ fn run_camera_controller(
}); });
let right = *transform.right() * engine.thrust_sideways * engine.current_warmup; let right = *transform.right() * engine.thrust_sideways * engine.current_warmup;
let up = *transform.up() * engine.thrust_sideways * engine.current_warmup; let up = *transform.up() * engine.thrust_sideways * engine.current_warmup;
actor.v += controller.velocity.x * dt * right actor.v += acceleration.x * dt * right
+ controller.velocity.y * dt * up + acceleration.y * dt * up
+ controller.velocity.z * dt * forward; + acceleration.z * dt * forward;
controller.velocity = Vec3::ZERO;
// Handle mouse input // Handle mouse input
let mut mouse_delta = Vec2::ZERO; let mut mouse_delta = Vec2::ZERO;