This commit is contained in:
yuni 2024-03-29 02:40:55 +01:00
parent ac747ac9c3
commit 8f682ee5b6
2 changed files with 10 additions and 27 deletions

View file

@ -1,6 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::{nature, settings, actor, audio, hud}; use crate::{nature, settings, actor, audio, hud};
pub const ENGINE_SPEED_FACTOR: f32 = 30.0;
const MIN_INTERACT_DISTANCE: f32 = 30.0; const MIN_INTERACT_DISTANCE: f32 = 30.0;
const NO_RIDE: u32 = 0; const NO_RIDE: u32 = 0;

View file

@ -98,32 +98,18 @@ fn run_camera_controller(
if key_input.pressed(settings.key_down) { if key_input.pressed(settings.key_down) {
axis_input.y -= 1.0; axis_input.y -= 1.0;
} }
} if key_input.pressed(settings.key_stop) {
let stop_direction = -actor.v.normalize();
if key_input.pressed(settings.key_stop) { if stop_direction.length_squared() > 0.3 {
if actor.v.length_squared() < 1e-6 { axis_input += 0.7 * (transform.rotation.inverse() * stop_direction);
actor.v = Vec3::ZERO; }
} }
} }
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 mut acceleration_camera: Vec3; let forward_factor = engine.current_warmup * (if axis_input.z < 0.0 {
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 {
engine.thrust_forward engine.thrust_forward
} else { } else {
engine.thrust_back engine.thrust_back
@ -132,13 +118,9 @@ fn run_camera_controller(
let up_factor = engine.thrust_sideways * engine.current_warmup; let up_factor = engine.thrust_sideways * engine.current_warmup;
let factor = Vec3::new(right_factor, up_factor, forward_factor); let factor = Vec3::new(right_factor, up_factor, forward_factor);
if acceleration_camera.length_squared() > 0.3 { if axis_input.length_squared() > 0.003 {
let acceleration_global = transform.rotation * (acceleration_camera.normalize() * factor); let acceleration_global = transform.rotation * (axis_input.normalize() * factor);
dbg!(acceleration_camera); actor.v += actor::ENGINE_SPEED_FACTOR * dt * acceleration_global;
dbg!(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); 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;