4 float sv_airaccelerate;
8 float sv_airaccel_sideways_friction;
11 .entity ladder_entity;
13 .float swamp_slowdown;
17 #define SHTEST_DELTA 15
19 .float shtest_accumulator;
25 When you press the jump key
28 void PlayerJump (void)
32 mjumpheight = cvar("sv_jumpvelocity");
33 if (self.waterlevel >= 2)
35 if (self.watertype == CONTENT_WATER)
36 self.velocity_z = 200;
37 else if (self.watertype == CONTENT_SLIME)
46 if (!(self.flags & FL_ONGROUND))
49 if (!(self.flags & FL_JUMPRELEASED))
52 if(cvar("g_runematch"))
54 if(self.runes & RUNE_SPEED)
56 if(self.runes & CURSE_SLOW)
57 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
59 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
61 else if(self.runes & CURSE_SLOW)
63 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
67 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
69 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
72 self.velocity_z = self.velocity_z + mjumpheight;
73 self.oldvelocity_z = self.velocity_z;
75 self.flags = self.flags - FL_ONGROUND;
76 self.flags = self.flags - FL_JUMPRELEASED;
79 void() CheckWaterJump =
81 local vector start, end;
83 // check for a jump-out-of-water
84 makevectors (self.angles);
86 start_z = start_z + 8;
89 end = start + v_forward*24;
90 traceline (start, end, TRUE, self);
91 if (trace_fraction < 1)
93 start_z = start_z + self.maxs_z - 8;
94 end = start + v_forward*24;
95 self.movedir = trace_plane_normal * -50;
96 traceline (start, end, TRUE, self);
97 if (trace_fraction == 1)
98 { // open at eye level
99 self.flags = self.flags | FL_WATERJUMP;
100 self.velocity_z = 225;
101 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
102 self.teleport_time = time + 2; // safety net
109 void Nixnex_GiveCurrentWeapon();
110 void SV_PlayerPhysics()
112 local vector wishvel, wishdir, v;
113 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score;
116 if(time > self.shtest_next)
118 if(self.shtest_next > 0)
120 // self.shtest_accumulator:
121 // started at time - SHTEST_DELTA
122 // should be at SHTEST_DELTA
123 shtest_score = self.shtest_accumulator / SHTEST_DELTA;
124 if(shtest_score > 1.2)
125 dprint("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
126 else if(cvar("developer_shtest"))
127 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
129 self.shtest_next = time + SHTEST_DELTA;
130 self.shtest_accumulator = 0;
132 self.shtest_accumulator += frametime;
134 if (clienttype(self) == CLIENTTYPE_BOT)
137 if (self.movetype == MOVETYPE_NONE)
140 if (self.punchangle != '0 0 0')
142 f = vlen(self.punchangle) - 10 * frametime;
144 self.punchangle = normalize(self.punchangle) * f;
146 self.punchangle = '0 0 0';
149 if (self.punchvector != '0 0 0')
151 f = vlen(self.punchvector) - 30 * frametime;
153 self.punchvector = normalize(self.punchvector) * f;
155 self.punchvector = '0 0 0';
160 if(cvar("g_runematch"))
162 if(self.runes & RUNE_SPEED)
164 if(self.runes & CURSE_SLOW)
165 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
167 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
169 else if(self.runes & CURSE_SLOW)
171 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
175 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
177 maxspd_mod = cvar("g_balance_rune_speed_moverate");
182 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
185 if(self.flags & FL_NOTARGET)
186 maxspd_mod = cvar("sv_spectator_speed_multiplier");
188 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
190 if(self.speed != spd)
194 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
195 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
196 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
197 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
199 temps = ftos(sv_accelerate * maxspd_mod);
200 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
203 // if dead, behave differently
210 self.angles_y = self.v_angle_y;
214 if(self.classname == "player")
219 self.flags = self.flags | FL_JUMPRELEASED;
221 if (self.waterlevel == 2)
225 if (self.flags & FL_WATERJUMP )
227 self.velocity_x = self.movedir_x;
228 self.velocity_y = self.movedir_y;
229 if (time > self.teleport_time || self.waterlevel == 0)
231 self.flags = self.flags - (self.flags & FL_WATERJUMP);
232 self.teleport_time = 0;
235 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
237 // noclipping or flying
238 self.flags = self.flags - (self.flags & FL_ONGROUND);
240 self.velocity = self.velocity * (1 - frametime * sv_friction);
241 makevectors(self.v_angle);
242 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
243 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
245 wishdir = normalize(wishvel);
246 wishspeed = vlen(wishvel);
247 if (wishspeed > sv_maxspeed*maxspd_mod)
248 wishspeed = sv_maxspeed*maxspd_mod;
249 if (time >= self.teleport_time)
251 f = wishspeed - (self.velocity * wishdir);
253 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
256 else if (self.waterlevel >= 2)
259 self.flags = self.flags - (self.flags & FL_ONGROUND);
261 makevectors(self.v_angle);
262 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
263 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
264 if (wishvel == '0 0 0')
265 wishvel = '0 0 -60'; // drift towards bottom
267 wishdir = normalize(wishvel);
268 wishspeed = vlen(wishvel);
269 if (wishspeed > sv_maxspeed*maxspd_mod)
270 wishspeed = sv_maxspeed*maxspd_mod;
271 wishspeed = wishspeed * 0.7;
274 self.velocity = self.velocity * (1 - frametime * sv_friction);
276 // water acceleration
277 f = wishspeed - (self.velocity * wishdir);
279 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
281 else if (time < self.ladder_time)
283 // on a func_ladder or swimming in func_water
284 self.flags = self.flags - (self.flags & FL_ONGROUND);
286 self.velocity = self.velocity * (1 - frametime * sv_friction);
287 makevectors(self.v_angle);
288 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
289 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
291 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
293 self.velocity_z = self.velocity_z + sv_gravity * frametime;
294 if (self.ladder_entity.classname == "func_water")
297 if (f > self.ladder_entity.speed)
298 wishvel = wishvel * (self.ladder_entity.speed / f);
300 self.watertype = self.ladder_entity.skin;
301 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
302 if ((self.origin_z + self.view_ofs_z) < f)
304 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
306 else if ((self.origin_z + self.mins_z + 1) < f)
311 self.watertype = CONTENT_EMPTY;
315 wishdir = normalize(wishvel);
316 wishspeed = vlen(wishvel);
317 if (wishspeed > sv_maxspeed)
318 wishspeed = sv_maxspeed;
319 if (time >= self.teleport_time)
321 f = wishspeed - (self.velocity * wishdir);
323 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
326 else if (self.flags & FL_ONGROUND)
329 makevectors(self.v_angle_y * '0 1 0');
330 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
332 if(!(self.lastflags & FL_ONGROUND))
334 if(cvar("speedmeter"))
335 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
336 if(self.lastground < time - 0.3)
337 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
338 if(self.jumppadcount > 1)
339 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
340 self.jumppadcount = 0;
343 if (self.velocity_x || self.velocity_y)
344 if (!(self.flags & FL_JUMPRELEASED) || !self.button2)
349 if (f < sv_stopspeed)
350 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
352 f = 1 - frametime * sv_friction;
354 self.velocity = self.velocity * f;
356 self.velocity = '0 0 0';
359 wishdir = normalize(wishvel);
360 wishspeed = vlen(wishvel);
361 if (wishspeed > sv_maxspeed*maxspd_mod)
362 wishspeed = sv_maxspeed*maxspd_mod;
364 wishspeed = wishspeed * 0.5;
365 if (time >= self.teleport_time)
367 f = wishspeed - (self.velocity * wishdir);
369 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
376 maxairspd = sv_maxairspeed*maxspd_mod;
377 airaccel = sv_airaccelerate*maxspd_mod;
381 maxairspd = sv_maxairspeed;
382 airaccel = sv_airaccelerate;
385 makevectors(self.v_angle_y * '0 1 0');
386 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
388 wishdir = normalize(wishvel);
389 wishspeed = vlen(wishvel);
390 if (wishspeed > maxairspd)
391 wishspeed = maxairspd;
393 wishspeed = wishspeed * 0.5;
394 if (time >= self.teleport_time)
396 // NOTE: this does the same as the commented out old code if:
398 // sv_airaccel_sideways_friction 0
403 vel_straight = self.velocity * wishdir;
404 vel_z = self.velocity_z;
405 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
407 f = wishspeed - vel_straight;
409 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
411 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
413 // anti-sideways friction to fix QW-style bunnyhopping
414 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
416 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
419 f = wishspeed;// - (self.velocity * wishdir);
421 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
426 if(self.flags & FL_ONGROUND)
427 self.lastground = time;
429 self.lastflags = self.flags;