come to a full stop when braking while slow

This commit is contained in:
yuni 2024-03-29 02:56:48 +01:00
parent 0717495d57
commit b3885aa4b6

View file

@ -126,8 +126,20 @@ fn run_camera_controller(
if axis_input.length_squared() > 0.003 {
let acceleration_global = transform.rotation * (axis_input * factor);
actor.v += actor::ENGINE_SPEED_FACTOR * dt * acceleration_global;
let mut acceleration_total = actor::ENGINE_SPEED_FACTOR * dt * acceleration_global;
let threshold = 1e-5;
if key_input.pressed(settings.key_stop) {
for i in 0..3 {
if actor.v[i].abs() < threshold {
actor.v[i] = 0.0;
}
else if (actor.v[i] < 0.0 && actor.v[i] + acceleration_total[i] > 0.0) || (actor.v[i] > 0.0 && actor.v[i] + acceleration_total[i] < 0.0) {
actor.v[i] = 0.0;
acceleration_total[i] = 0.0;
}
}
}
actor.v += acceleration_total;
engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0);
play_thruster_sound = !settings.mute_sfx;
}