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
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 {
vel = Vec3::ZERO;
} else {
let drag = vel * settings.drag * v2 * dt;
vel -= drag;
if !vel.is_finite() {
vel = Vec3::ZERO;
}
pstate.velocity = vel;