clamp input vector, allowing slow motion while holding space

In typical games we would normalize the input vector so that diagonal
movement is as fast as forward or sideways movement.  But here, we
merely clamp each direction to an absolute maximum of 1, since every
thruster can be used separately. If the forward thrusters and the
leftward thrusters are active at the same time, then of course the total
diagonal acceleration is faster than the forward acceleration alone.
This commit is contained in:
yuni 2024-03-29 02:41:05 +01:00
parent 8f682ee5b6
commit dd49906cce

View file

@ -101,10 +101,16 @@ fn run_camera_controller(
if key_input.pressed(settings.key_stop) {
let stop_direction = -actor.v.normalize();
if stop_direction.length_squared() > 0.3 {
axis_input += 0.7 * (transform.rotation.inverse() * stop_direction);
axis_input += 0.8 * (transform.rotation.inverse() * stop_direction);
}
}
}
// In typical games we would normalize the input vector so that diagonal movement is as
// fast as forward or sideways movement. But here, we merely clamp each direction to an
// absolute maximum of 1, since every thruster can be used separately. If the forward
// thrusters and the leftward thrusters are active at the same time, then of course the
// total diagonal acceleration is faster than the forward acceleration alone.
axis_input = axis_input.clamp(Vec3::splat(-1.0), Vec3::splat(1.0));
let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine };
@ -119,7 +125,7 @@ fn run_camera_controller(
let factor = Vec3::new(right_factor, up_factor, forward_factor);
if axis_input.length_squared() > 0.003 {
let acceleration_global = transform.rotation * (axis_input.normalize() * factor);
let acceleration_global = transform.rotation * (axis_input * factor);
actor.v += actor::ENGINE_SPEED_FACTOR * dt * acceleration_global;
engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0);