add engine warm up time

This commit is contained in:
yuni 2024-03-29 00:01:17 +01:00
parent a25b249bb8
commit 4111f16454
4 changed files with 27 additions and 8 deletions

View file

@ -151,6 +151,8 @@ pub struct Engine {
pub thrust_sideways: f32, pub thrust_sideways: f32,
pub reaction_wheels: f32, pub reaction_wheels: f32,
pub engine_type: EngineType, pub engine_type: EngineType,
pub warmup_seconds: f32,
pub current_warmup: f32,
} }
impl Default for Engine { impl Default for Engine {
fn default() -> Self { fn default() -> Self {
@ -160,6 +162,8 @@ impl Default for Engine {
thrust_sideways: 1.0, thrust_sideways: 1.0,
reaction_wheels: 1.0, reaction_wheels: 1.0,
engine_type: EngineType::Monopropellant, engine_type: EngineType::Monopropellant,
warmup_seconds: 1.5,
current_warmup: 0.0,
} }
} }
} }

View file

@ -53,8 +53,15 @@ fn run_camera_controller(
key_input: Res<ButtonInput<KeyCode>>, key_input: Res<ButtonInput<KeyCode>>,
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>, thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>, rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
q_engine: Query<&actor::Engine, With<actor::PlayerDrivesThis>>, mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
mut query: Query<(&mut Transform, &mut CameraController, &mut Projection, &mut actor::Actor, &actor::LifeForm, &actor::Engine), With<Camera>>, mut query: Query<(
&mut Transform,
&mut CameraController,
&mut Projection,
&mut actor::Actor,
&actor::LifeForm,
&mut actor::Engine
), (With<Camera>, Without<actor::PlayerDrivesThis>)>,
) { ) {
let dt = time.delta_seconds(); let dt = time.delta_seconds();
let mut play_thruster_sound = false; let mut play_thruster_sound = false;
@ -111,25 +118,28 @@ fn run_camera_controller(
0.0 0.0
}; };
let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine };
// Apply movement update // Apply movement update
if axis_input != Vec3::ZERO { if axis_input != Vec3::ZERO {
let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed; let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed;
controller.velocity = new_velocity; controller.velocity = new_velocity;
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; controller.velocity *= 1.0 - friction;
engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0);
if controller.velocity.length_squared() < 1e-6 { if controller.velocity.length_squared() < 1e-6 {
controller.velocity = Vec3::ZERO; controller.velocity = Vec3::ZERO;
} }
} }
let engine = if let Ok(engine) = q_engine.get_single() { engine } else { player_engine }; let forward = *transform.forward() * engine.current_warmup * (if axis_input.z > 0.0 {
let forward = *transform.forward() * (if axis_input.z > 0.0 {
engine.thrust_forward engine.thrust_forward
} else { } else {
engine.thrust_back engine.thrust_back
}); });
let right = *transform.right() * engine.thrust_sideways; let right = *transform.right() * engine.thrust_sideways * engine.current_warmup;
actor.v += controller.velocity.x * dt * right actor.v += controller.velocity.x * dt * right
+ controller.velocity.y * dt * Vec3::Y + controller.velocity.y * dt * Vec3::Y
+ controller.velocity.z * dt * forward; + controller.velocity.z * dt * forward;

View file

@ -80,7 +80,7 @@ actor 3650 230 5000 asteroid1
actor 10 -30 20 MeteorAceGT actor 10 -30 20 MeteorAceGT
scale 5 scale 5
vehicle yes vehicle yes
thrust 70 13.7 9.4 0.5 thrust 70 13.7 9.4 0.5 20
engine rocket engine rocket
actor 10 0 70 suit actor 10 0 70 suit

View file

@ -245,6 +245,7 @@ struct ParserState {
thrust_sideways: f32, thrust_sideways: f32,
thrust_back: f32, thrust_back: f32,
reaction_wheels: f32, reaction_wheels: f32,
warmup_seconds: f32,
engine_type: actor::EngineType, engine_type: actor::EngineType,
oxygen: f32, oxygen: f32,
@ -284,6 +285,7 @@ impl Default for ParserState {
thrust_sideways: default_engine.thrust_forward, thrust_sideways: default_engine.thrust_forward,
thrust_back: default_engine.thrust_back, thrust_back: default_engine.thrust_back,
reaction_wheels: default_engine.reaction_wheels, reaction_wheels: default_engine.reaction_wheels,
warmup_seconds: default_engine.warmup_seconds,
engine_type: default_engine.engine_type, engine_type: default_engine.engine_type,
oxygen: nature::OXY_D, oxygen: nature::OXY_D,
@ -358,7 +360,9 @@ impl ParserState {
thrust_back: self.thrust_back, thrust_back: self.thrust_back,
thrust_sideways: self.thrust_sideways, thrust_sideways: self.thrust_sideways,
reaction_wheels: self.reaction_wheels, reaction_wheels: self.reaction_wheels,
warmup_seconds: self.warmup_seconds,
engine_type: self.engine_type, engine_type: self.engine_type,
..default()
}; };
let component_suit = actor::Suit { let component_suit = actor::Suit {
oxygen: self.oxygen, oxygen: self.oxygen,
@ -551,12 +555,13 @@ pub fn load_defs(
continue; continue;
} }
} }
["thrust", forward, back, sideways, reaction_wheels] => { ["thrust", forward, back, sideways, reaction_wheels, warmup_time] => {
if let (Ok(forward_float), Ok(back_float), Ok(sideways_float), Ok(reaction_wheels_float)) = (forward.parse::<f32>(), back.parse::<f32>(), sideways.parse::<f32>(), reaction_wheels.parse::<f32>()) { if let (Ok(forward_float), Ok(back_float), Ok(sideways_float), Ok(reaction_wheels_float), Ok(warmup_time_float)) = (forward.parse::<f32>(), back.parse::<f32>(), sideways.parse::<f32>(), reaction_wheels.parse::<f32>(), warmup_time.parse::<f32>()) {
state.thrust_forward = forward_float; state.thrust_forward = forward_float;
state.thrust_back = back_float; state.thrust_back = back_float;
state.thrust_sideways = sideways_float; state.thrust_sideways = sideways_float;
state.reaction_wheels = reaction_wheels_float; state.reaction_wheels = reaction_wheels_float;
state.warmup_seconds = warmup_time_float;
} }
} }
["engine", "rocket"] => { ["engine", "rocket"] => {