From f101929a9dc6017f9596a298d98af4d10fbbabad Mon Sep 17 00:00:00 2001 From: TheJoeCoder <joe@radialbog9.uk> Date: Mon, 5 Aug 2024 13:01:30 +0100 Subject: [PATCH] Fix velocity clamping to initial --- static/js/background_anim.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/static/js/background_anim.js b/static/js/background_anim.js index f835fdb..2a78cb6 100644 --- a/static/js/background_anim.js +++ b/static/js/background_anim.js @@ -235,11 +235,19 @@ const physics = () => { dot.xy *= VELOCITY_SLOWDOWN_MULTIPLIER; // Stop velocity from going below initial velocity - if(dot.vx < dot.initial_vx) { - dot.vx = dot.initial_vx; + if(Math.abs(dot.vx) < Math.abs(dot.initial_vx)) { + if((dot.vx > 0 && dot.initial_vx > 0) || (dot.vx < 0 && dot.initial_vx < 0)) { + dot.vx = dot.initial_vx; + } else { + dot.vx = -dot.initial_vx; + } } - if(dot.vy < dot.initial_vy) { - dot.vy = dot.initial_vy; + if(Math.abs(dot.vy) < Math.abs(dot.initial_vy)) { + if((dot.vy > 0 && dot.initial_vy > 0) || (dot.vy < 0 && dot.initial_vy < 0)) { + dot.vy = dot.initial_vy; + } else { + dot.vy = -dot.initial_vy; + } } // Invert velocities if off-screen and not already inverted -- GitLab