From 9a23c6b295224fae081160109d39612fd8443592 Mon Sep 17 00:00:00 2001 From: div0 Date: Sat, 30 Jan 2010 18:07:53 +0000 Subject: [PATCH] make CPMA aircontrol code more logical git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8595 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_physics.qc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/data/qcsrc/server/cl_physics.qc b/data/qcsrc/server/cl_physics.qc index d0a5bb17c..533a26e35 100644 --- a/data/qcsrc/server/cl_physics.qc +++ b/data/qcsrc/server/cl_physics.qc @@ -384,15 +384,17 @@ void RaceCarPhysics() self.angles_z = smoothangles_z; } -float IsMoveInDirection(vector mv, float angle) +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 = remainder(angle, 360) / 22.5; + angle = remainder(angle, 360) / 45; if(angle > 1) return 0; if(angle < -1) return 0; - return 1 - angle * angle; + return 1 - fabs(angle); } void CPM_PM_Aircontrol(vector wishdir, float wishspeed) @@ -405,21 +407,24 @@ void CPM_PM_Aircontrol(vector wishdir, float wishspeed) return; // can't control movement if not moving forward or backward k = 32; #else - k = 32 * IsMoveInDirection(self.movement, 0); + k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1); if(k <= 0) return; #endif + k *= bound(0, wishspeed / maxairspd, 1); + zspeed = self.velocity_z; self.velocity_z = 0; - xyspeed = vlen(self.velocity); - self.velocity = normalize(self.velocity); + xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity); dot = self.velocity * wishdir; k *= sv_aircontrol*dot*dot*frametime; if(dot > 0) // we can't change direction while slowing down + { self.velocity = normalize(self.velocity * xyspeed + wishdir * k); + } self.velocity = self.velocity * xyspeed; self.velocity_z = zspeed; -- 2.39.2