WIP crisper camera controls (add visual effects, engine parameters)
This commit is contained in:
parent
94bf21b340
commit
8fcb702623
61
src/actor.rs
61
src/actor.rs
|
@ -737,7 +737,8 @@ fn handle_wants_acceleration(
|
|||
Option<&WantsAcceleration>,
|
||||
Option<&hud::IsTargeted>,
|
||||
Option<&PlayerCamera>,
|
||||
)>,
|
||||
), Without<visual::IsEffect>>,
|
||||
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
|
||||
|
@ -795,19 +796,61 @@ fn handle_wants_acceleration(
|
|||
// Finally, apply the requested acceleration to the actor's velocity
|
||||
let mut play_thruster_sound = false;
|
||||
let mut players_engine: Option<Engine> = None;
|
||||
for (entity, trans, _, mut v, engine, accel, _, is_player) in &mut q_actor {
|
||||
for (entity, trans, pos, mut v, engine, accel, _, is_player) in &mut q_actor {
|
||||
let mut thruster_on = false;
|
||||
if let (Some(engine), Some(accel)) = (engine, accel) {
|
||||
if let (Some(mut engine), Some(accel)) = (engine, accel) {
|
||||
let mut delta_v = DVec3::ZERO;
|
||||
let boost = engine.current_boost_factor;
|
||||
|
||||
if accel.brake {
|
||||
if let Some(target_v) = closest_map.get(&entity) {
|
||||
**v = *target_v;
|
||||
thruster_on = true;
|
||||
}
|
||||
} else if accel.direction != DVec3::ZERO {
|
||||
let delta_v = trans.rotation * accel.direction.as_vec3();
|
||||
**v += delta_v.as_dvec3();
|
||||
thruster_on = true;
|
||||
delta_v = (trans.rotation * accel.direction.as_vec3()).as_dvec3();
|
||||
}
|
||||
|
||||
if delta_v.length_squared() > 0.003 {
|
||||
// Engine is firing!
|
||||
thruster_on = true;
|
||||
engine.current_warmup =
|
||||
(engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0);
|
||||
|
||||
// Adjust acceleration to what the engine can actually provide
|
||||
let forward_factor = engine.current_warmup
|
||||
* (if accel.direction.z > 0.0 {
|
||||
engine.thrust_forward
|
||||
} else {
|
||||
engine.thrust_back
|
||||
});
|
||||
let right_factor = engine.thrust_sideways * engine.current_warmup;
|
||||
let up_factor = engine.thrust_sideways * engine.current_warmup;
|
||||
let factor =
|
||||
DVec3::new(right_factor as f64, up_factor as f64, forward_factor as f64);
|
||||
|
||||
// Apply acceleration to velocity
|
||||
**v += delta_v * factor;
|
||||
|
||||
// Visual effect
|
||||
if engine.engine_type == EngineType::Monopropellant {
|
||||
let thruster_direction = delta_v.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 {
|
||||
duration: 2.0,
|
||||
class: visual::Effects::ThrusterParticle(
|
||||
Position::from(thruster_pos),
|
||||
LinearVelocity::from(thruster_v),
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Engine is not firing
|
||||
engine.current_warmup =
|
||||
(engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0);
|
||||
}
|
||||
|
||||
if is_player.is_some() {
|
||||
play_thruster_sound = thruster_on;
|
||||
players_engine = Some((*engine).clone());
|
||||
|
@ -830,7 +873,7 @@ fn handle_wants_acceleration(
|
|||
let sinks = vec![
|
||||
(
|
||||
1.0,
|
||||
1.0, //boost as f32,
|
||||
engine.current_boost_factor as f32,
|
||||
actor::EngineType::Monopropellant,
|
||||
sinks.get(&audio::Sfx::Thruster),
|
||||
),
|
||||
|
@ -856,9 +899,7 @@ fn handle_wants_acceleration(
|
|||
sink.set_speed(speed);
|
||||
sink.play();
|
||||
if volume < maxvol {
|
||||
sink.set_volume(
|
||||
(volume + dt / seconds_to_max_vol).clamp(0.0, maxvol),
|
||||
);
|
||||
sink.set_volume((volume + dt / seconds_to_max_vol).clamp(0.0, maxvol));
|
||||
}
|
||||
} else {
|
||||
sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, maxvol));
|
||||
|
|
Loading…
Reference in a new issue