From 162da719ee2382562fd7053cbe93dfa589d85246 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 30 Apr 2022 00:51:30 +0200 Subject: Changed to use factor-based velocity damping --- Player.cpp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/Player.cpp b/Player.cpp index 94371c1..facfaf4 100644 --- a/Player.cpp +++ b/Player.cpp @@ -1,6 +1,7 @@ #include "Player.h" #include +#include #include #include @@ -10,7 +11,7 @@ static constexpr float ACCELERATION {1800}; static constexpr float MAX_SPEED {180}; -static constexpr float DAMP {2200}; +static constexpr float DAMP {3e-10f}; static constexpr float MARGIN {0.3f}; static constexpr float HIT_INVUL {1.2f}; static constexpr float RADIUS {4}; @@ -74,25 +75,12 @@ damped_velocity(const float dt, const float direction, const float velocity) { if (direction > 0 || direction < 0) return velocity + direction * ACCELERATION * dt; - if (velocity > 0) { - if (velocity > MARGIN) { - const float next = velocity - dt * DAMP; - if (next < MARGIN) - return 0; - else - return next; - } - return 0; - } - if (velocity < 0) { - if (velocity < MARGIN) { - const float next = velocity + dt * DAMP; - if (next > MARGIN) - return 0; - else - return next; - } - return 0; + if (velocity > MARGIN || velocity < -MARGIN) { + const float next = velocity * std::pow(DAMP, dt); + if (next < MARGIN && next > -MARGIN) + return 0; + else + return next; } return 0; } -- cgit v1.1