- // ensure we don't get too fast or decelerate faster than we should
- vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
- if(vel_xy_current > 0) // prevent division by zero
- vel_xy = normalize(vel_xy) * vel_xy_current;
+ float vel_xy_preclamp;
+ vel_xy_preclamp = vlen(vel_xy);
+ if(vel_xy_preclamp > 0) // prevent division by zero
+ {
+ vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
+ if(vel_xy_current < vel_xy_preclamp)
+ vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
+ }