diff options
-rw-r--r-- | Player.cpp | 28 |
1 files changed, 8 insertions, 20 deletions
@@ -1,6 +1,7 @@ #include "Player.h" #include <algorithm> +#include <cmath> #include <memory> #include <raylib.h> @@ -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; } |