Smarter vel zeroing.

This commit is contained in:
Joe Ardent 2022-01-12 21:13:30 +00:00
parent 26f2331743
commit 3ebe2f57ce

View file

@ -89,12 +89,8 @@ fn update_player_vel(
}; };
// thrust or brake // thrust or brake
let accel = xform.forward() * input.throttle * dt * settings.accel; vel += xform.forward() * input.throttle * dt * settings.accel;
if pstate.velocity.is_finite() {
vel += accel;
} else {
vel = accel;
}
// brake // brake
if input.brake { if input.brake {
@ -108,11 +104,11 @@ fn update_player_vel(
// drag // drag
let v2 = vel.length_squared().min(100_000.0); let v2 = vel.length_squared().min(100_000.0);
if v2 < 0.05 { let drag = vel * settings.drag * v2 * dt;
vel -= drag;
if !vel.is_finite() {
vel = Vec3::ZERO; vel = Vec3::ZERO;
} else {
let drag = vel * settings.drag * v2 * dt;
vel -= drag;
} }
pstate.velocity = vel; pstate.velocity = vel;