]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_physics.qc
new physics cvar: sv_airstrafeaccel_qw; also try to fix analog input issues with...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_physics.qc
index ff5fbaa37ee4cf436796d3bc709e8164993c5de6..defb1f93925d014e3da2d9078d989c436b194de5 100644 (file)
@@ -13,6 +13,7 @@ float sv_airaccel_qw;
 float sv_airstopaccelerate;
 float sv_airstrafeaccelerate;
 float sv_maxairstrafespeed;
+float sv_airstrafeaccel_qw;
 float sv_aircontrol;
 float sv_aircontrol_power;
 float sv_warsowbunny_airforwardaccel;
@@ -386,7 +387,7 @@ float IsMoveInDirection(vector mv, float angle) // key mix factor
 {
        if(mv_x == 0 && mv_y == 0)
                return 0; // avoid division by zero
-       angle = RAD2DEG * atan2(mv_y, mv_x);
+       angle -= RAD2DEG * atan2(mv_y, mv_x);
        angle = remainder(angle, 360) / 45;
        if(angle >  1)
                return 0;
@@ -395,6 +396,25 @@ float IsMoveInDirection(vector mv, float angle) // key mix factor
        return 1 - fabs(angle);
 }
 
+float GeomLerp(float a, float lerp, float b)
+{
+       if(a == 0)
+       {
+               if(lerp < 1)
+                       return 0;
+               else
+                       return b;
+       }
+       if(b == 0)
+       {
+               if(lerp > 0)
+                       return 0;
+               else
+                       return a;
+       }
+       return a * pow(fabs(b / a), lerp);
+}
+
 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
 {
        float zspeed, xyspeed, dot, k;
@@ -1138,6 +1158,7 @@ void SV_PlayerPhysics()
                        float accelerating;
                        float wishspeed2;
                        float airaccelqw;
+                       float strafity;
 
                        airaccelqw = sv_airaccel_qw;
                        accelerating = (self.velocity * wishdir > 0);
@@ -1150,21 +1171,21 @@ void SV_PlayerPhysics()
                        // this doesn't play well with analog input, but can't r
                        // fixed like the AirControl can. So, don't set the maxa
                        // cvars when you want to support analog input.
-                       if(self.movement_x == 0 && self.movement_y != 0)
-                       {
-                               if(sv_maxairstrafespeed)
-                               {
-                                       wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
-                                       if(sv_maxairstrafespeed < sv_maxairspeed)
-                                               airaccelqw = 1;
-                               }
-                               if(sv_airstrafeaccelerate)
-                               {
-                                       airaccel = sv_airstrafeaccelerate*maxspd_mod;
-                                       if(sv_airstrafeaccelerate > sv_airaccelerate)
-                                               airaccelqw = 1;
-                               }
-                       }
+                       // note that for straight forward jumping:
+                       // step = accel * frametime * wishspeed0;
+                       // accel  = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
+                       // -->
+                       // dv/dt = accel * maxspeed (when slow)
+                       // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
+                       // log dv/dt = logaccel + logmaxspeed (when slow)
+                       // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
+                       strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
+                       if(sv_maxairstrafespeed)
+                               wishspeed = min(wishspeed, GeomLerp(sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod));
+                       if(sv_airstrafeaccelerate)
+                               airaccel = GeomLerp(airaccel, strafity, sv_airstrafeaccelerate*maxspd_mod);
+                       if(sv_airstrafeaccel_qw)
+                               airaccelqw = sign((strafity > 0.5) ? sv_airstrafeaccel_qw : sv_airaccel_qw) * (1-GeomLerp(1-fabs(airaccelqw), strafity, 1-fabs(sv_airstrafeaccel_qw)));
                        // !CPM
 
                        if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)