add engine warm up time
This commit is contained in:
parent
a25b249bb8
commit
4111f16454
|
@ -151,6 +151,8 @@ pub struct Engine {
|
|||
pub thrust_sideways: f32,
|
||||
pub reaction_wheels: f32,
|
||||
pub engine_type: EngineType,
|
||||
pub warmup_seconds: f32,
|
||||
pub current_warmup: f32,
|
||||
}
|
||||
impl Default for Engine {
|
||||
fn default() -> Self {
|
||||
|
@ -160,6 +162,8 @@ impl Default for Engine {
|
|||
thrust_sideways: 1.0,
|
||||
reaction_wheels: 1.0,
|
||||
engine_type: EngineType::Monopropellant,
|
||||
warmup_seconds: 1.5,
|
||||
current_warmup: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,15 @@ fn run_camera_controller(
|
|||
key_input: Res<ButtonInput<KeyCode>>,
|
||||
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
|
||||
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
|
||||
q_engine: Query<&actor::Engine, With<actor::PlayerDrivesThis>>,
|
||||
mut query: Query<(&mut Transform, &mut CameraController, &mut Projection, &mut actor::Actor, &actor::LifeForm, &actor::Engine), With<Camera>>,
|
||||
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
|
||||
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 mut play_thruster_sound = false;
|
||||
|
@ -111,25 +118,28 @@ fn run_camera_controller(
|
|||
0.0
|
||||
};
|
||||
|
||||
let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine };
|
||||
|
||||
// Apply movement update
|
||||
if axis_input != Vec3::ZERO {
|
||||
let new_velocity = controller.velocity + 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);
|
||||
play_thruster_sound = !settings.mute_sfx;
|
||||
} else {
|
||||
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 {
|
||||
controller.velocity = Vec3::ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
let engine = if let Ok(engine) = q_engine.get_single() { engine } else { player_engine };
|
||||
let forward = *transform.forward() * (if axis_input.z > 0.0 {
|
||||
let forward = *transform.forward() * engine.current_warmup * (if axis_input.z > 0.0 {
|
||||
engine.thrust_forward
|
||||
} else {
|
||||
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
|
||||
+ controller.velocity.y * dt * Vec3::Y
|
||||
+ controller.velocity.z * dt * forward;
|
||||
|
|
|
@ -80,7 +80,7 @@ actor 3650 230 5000 asteroid1
|
|||
actor 10 -30 20 MeteorAceGT
|
||||
scale 5
|
||||
vehicle yes
|
||||
thrust 70 13.7 9.4 0.5
|
||||
thrust 70 13.7 9.4 0.5 20
|
||||
engine rocket
|
||||
|
||||
actor 10 0 70 suit
|
||||
|
|
|
@ -245,6 +245,7 @@ struct ParserState {
|
|||
thrust_sideways: f32,
|
||||
thrust_back: f32,
|
||||
reaction_wheels: f32,
|
||||
warmup_seconds: f32,
|
||||
engine_type: actor::EngineType,
|
||||
oxygen: f32,
|
||||
|
||||
|
@ -284,6 +285,7 @@ impl Default for ParserState {
|
|||
thrust_sideways: default_engine.thrust_forward,
|
||||
thrust_back: default_engine.thrust_back,
|
||||
reaction_wheels: default_engine.reaction_wheels,
|
||||
warmup_seconds: default_engine.warmup_seconds,
|
||||
engine_type: default_engine.engine_type,
|
||||
oxygen: nature::OXY_D,
|
||||
|
||||
|
@ -358,7 +360,9 @@ impl ParserState {
|
|||
thrust_back: self.thrust_back,
|
||||
thrust_sideways: self.thrust_sideways,
|
||||
reaction_wheels: self.reaction_wheels,
|
||||
warmup_seconds: self.warmup_seconds,
|
||||
engine_type: self.engine_type,
|
||||
..default()
|
||||
};
|
||||
let component_suit = actor::Suit {
|
||||
oxygen: self.oxygen,
|
||||
|
@ -551,12 +555,13 @@ pub fn load_defs(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
["thrust", forward, back, sideways, reaction_wheels] => {
|
||||
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>()) {
|
||||
["thrust", forward, back, sideways, reaction_wheels, warmup_time] => {
|
||||
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_back = back_float;
|
||||
state.thrust_sideways = sideways_float;
|
||||
state.reaction_wheels = reaction_wheels_float;
|
||||
state.warmup_seconds = warmup_time_float;
|
||||
}
|
||||
}
|
||||
["engine", "rocket"] => {
|
||||
|
|
Loading…
Reference in a new issue