if sideways friction is negative, make it never decrease total velocity (might be...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 Sep 2009 14:56:46 +0000 (14:56 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 Sep 2009 14:56:46 +0000 (14:56 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9194 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c

index 9b70e21..5568865 100644 (file)
@@ -1106,6 +1106,9 @@ void CL_ClientMovement_Physics_PM_Accelerate(cl_clientmovement_state_t *s, vec3_
        vec_t vel_straight, vel_z;
        vec3_t vel_perpend;
        vec_t addspeed;
+       vec_t savespeed;
+
+       savespeed = VectorLength2(s->velocity);
 
        vel_straight = DotProduct(s->velocity, wishdir);
        vel_z = s->velocity[2];
@@ -1117,7 +1120,18 @@ void CL_ClientMovement_Physics_PM_Accelerate(cl_clientmovement_state_t *s, vec3_
        if(wishspeed > 0)
                vel_straight = vel_straight + min(wishspeed, accel * s->cmd.frametime * wishspeed) * (1 - accelqw);
        
-       VectorScale(vel_perpend, 1 - s->cmd.frametime * wishspeed * sidefric, vel_perpend);
+       if(sidefric < 0 && VectorLength2(vel_perpend))
+       {
+               vec_t f, fmin;
+               f = 1 + s->cmd.frametime * wishspeed * sidefric;
+               fmin = (savespeed - vel_straight*vel_straight) / VectorLength2(vel_perpend);
+               if(fmin <= 0)
+                       VectorScale(vel_perpend, f, vel_perpend);
+               else
+                       VectorScale(vel_perpend, min(1.0f, max(fmin, f)), vel_perpend);
+       }
+       else
+               VectorScale(vel_perpend, 1 - s->cmd.frametime * wishspeed * sidefric, vel_perpend);
 
        VectorMA(vel_perpend, vel_straight, wishdir, s->velocity);
        s->velocity[2] += vel_z;