From 3ebe2f57ce13ce1f60f0dc568f4cff5859e39ff6 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 12 Jan 2022 21:13:30 +0000 Subject: [PATCH] Smarter vel zeroing. --- src/physics.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/physics.rs b/src/physics.rs index 3814b41..0efd978 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -89,12 +89,8 @@ fn update_player_vel( }; // thrust or brake - let accel = xform.forward() * input.throttle * dt * settings.accel; - if pstate.velocity.is_finite() { - vel += accel; - } else { - vel = accel; - } + vel += xform.forward() * input.throttle * dt * settings.accel; + // brake if input.brake { @@ -108,11 +104,11 @@ fn update_player_vel( // drag 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; - } else { - let drag = vel * settings.drag * v2 * dt; - vel -= drag; } pstate.velocity = vel;