shithub: qk1

Download patch

ref: 7b70a3e6d9caf58d84792c9c2ddd6547a13b7843
parent: e92454e8739ee80d9ae080d4abd76f0b6f6d4034
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Dec 28 12:41:19 EST 2023

SV_CheckVelocity: clamp max velocity correctly (thanks Maddes)

--- a/sv_phys.c
+++ b/sv_phys.c
@@ -36,6 +36,7 @@
 void SV_CheckVelocity (edict_t *ent)
 {
 	int		i;
+	float wishspeed;
 
 	// bound velocity
 	for (i=0 ; i<3 ; i++)
@@ -50,11 +51,10 @@
 			Con_Printf ("Got a NaN origin on %s\n", PR_Str(sv.pr, ent->v.classname));
 			ent->v.origin[i] = 0;
 		}
-		if (ent->v.velocity[i] > sv_maxvelocity.value)
-			ent->v.velocity[i] = sv_maxvelocity.value;
-		else if (ent->v.velocity[i] < -sv_maxvelocity.value)
-			ent->v.velocity[i] = -sv_maxvelocity.value;
 	}
+	wishspeed = Length(ent->v.velocity);
+	if(wishspeed > sv_maxvelocity.value)
+		VectorScale(ent->v.velocity, sv_maxvelocity.value/wishspeed, ent->v.velocity);
 }
 
 /*