{
float strafe_waterlevel;
- // get the player waterlevel without affecting the player entity
+ // get the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled
{
// store old values
void old_contentstransition(int, int) = strafeplayer.contentstransition;
float bestspeed;
float maxaccel_phys = onground ? PHYS_ACCELERATE(strafeplayer) : PHYS_AIRACCELERATE(strafeplayer);
float maxaccel = !autocvar__hud_configure ? maxaccel_phys : 1;
- float frametime_phys;
float vel_angle = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0); // change the range from 0° - 360° to -180° - 180° to match how view_angle represents angles
float view_angle = PHYS_INPUT_ANGLES(strafeplayer).y;
float angle;
// calculate the maximum air strafe speed and acceleration
float strafity = 1 - (90 - fabs(wishangle)) / 45;
- if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0){
+ if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0)
+ {
maxspeed = GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer));
maxspeed = min(maxspeed, PHYS_MAXAIRSPEED(strafeplayer) * maxspeed_mod);
}
if(turnspeed == 0) turnspeed = maxspeed;
else turnspeed = min(turnspeed, maxspeed);
- if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0) {
+ if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0)
+ {
maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer));
}
turnaccel = maxaccel;
}
maxaccel *= strafe_dt_avg * movespeed;
- bestspeed = max(movespeed - maxaccel, 0);
+ bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration
- float strafespeed = speed; // speed minus friction
+ float frictionspeed; // speed lost from friction
+ float strafespeed; // speed minus friction
- if((strafespeed > 0) && onground){
+ if((speed > 0) && onground)
+ {
float strafefriction = IS_ONSLICK(strafeplayer) ? PHYS_FRICTION_SLICK(strafeplayer) : PHYS_FRICTION(strafeplayer);
- float f = 1 - strafe_dt_avg * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / strafespeed, 1);
- if(f <= 0)
- strafespeed = 0;
- else
- strafespeed *= f;
+ frictionspeed = speed * strafe_dt_avg * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / speed, 1);
+ strafespeed = max(speed - frictionspeed, 0);
+ }
+ else
+ {
+ frictionspeed = 0;
+ strafespeed = speed;
}
- minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? bestspeed + (speed - strafespeed) : autocvar_hud_panel_strafehud_switch_minspeed;
+ minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? bestspeed + frictionspeed : autocvar_hud_panel_strafehud_switch_minspeed;
// get current strafing angle ranging from -180° to +180°
if(!autocvar__hud_configure)
// best angle to strafe at
bestangle = (strafespeed > bestspeed ? acos(bestspeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0);
- prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0);
+ prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0); // in case of ground friction we may decelerate if the acceleration is smaller than the speed loss from friction
odd_bestangle = -bestangle - wishangle;
bestangle -= wishangle;
prebestangle -= wishangle;
else if(mirror_offset == 0) gradient_start = 1;
else gradient_start = 0;
- switch(gradient_start){
+ switch(gradient_start)
+ {
default:
case 0: // no offset required
gradient_offset = gradient_mirror_offset = 0;