4 float sv_airaccelerate;
8 float sv_airaccel_sideways_friction;
11 .entity ladder_entity;
13 .float swamp_slowdown;
17 .float spectatorspeed;
19 #define SHTEST_DELTA 15
21 .float shtest_accumulator;
27 When you press the jump key
30 void PlayerJump (void)
34 mjumpheight = cvar("sv_jumpvelocity");
35 if (self.waterlevel >= 2)
37 if (self.watertype == CONTENT_WATER)
38 self.velocity_z = 200;
39 else if (self.watertype == CONTENT_SLIME)
48 if (!(self.flags & FL_ONGROUND))
52 if (!(self.flags & FL_JUMPRELEASED))
57 if(self.runes & RUNE_SPEED)
59 if(self.runes & CURSE_SLOW)
60 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
62 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
64 else if(self.runes & CURSE_SLOW)
66 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
70 if(g_minstagib && (self.items & IT_INVINCIBLE))
72 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
75 self.velocity_z = self.velocity_z + mjumpheight;
76 self.oldvelocity_z = self.velocity_z;
78 self.flags = self.flags - FL_ONGROUND;
79 self.flags = self.flags - FL_JUMPRELEASED;
82 player_setanim(self.anim_duckjump, FALSE, TRUE, TRUE);
84 player_setanim(self.anim_jump, FALSE, TRUE, TRUE);
87 PlayerSound(playersound_jump, CHAN_PLAYER, 0);
92 local vector start, end;
94 // check for a jump-out-of-water
95 makevectors (self.angles);
97 start_z = start_z + 8;
100 end = start + v_forward*24;
101 traceline (start, end, TRUE, self);
102 if (trace_fraction < 1)
104 start_z = start_z + self.maxs_z - 8;
105 end = start + v_forward*24;
106 self.movedir = trace_plane_normal * -50;
107 traceline (start, end, TRUE, self);
108 if (trace_fraction == 1)
109 { // open at eye level
110 self.flags = self.flags | FL_WATERJUMP;
111 self.velocity_z = 225;
112 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
113 self.teleport_time = time + 2; // safety net
119 .vector movement_old;
123 void Nixnex_GiveCurrentWeapon();
124 void SV_PlayerPhysics()
126 local vector wishvel, wishdir, v;
127 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
130 buttons = self.BUTTON_ATCK + 2 * self.BUTTON_JUMP + 4 * self.BUTTON_ATCK2 + 8 * self.BUTTON_ZOOM + 16 * self.BUTTON_CROUCH + 32 * self.BUTTON_HOOK + 64 * self.BUTTON_USE;
131 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
133 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
134 self.parm_idlesince = time;
136 self.buttons_old = buttons;
137 self.movement_old = self.movement;
138 self.v_angle_old = self.v_angle;
140 if(time > self.shtest_next)
142 if(self.shtest_next > 0)
144 // self.shtest_accumulator:
145 // started at time - SHTEST_DELTA
146 // should be at SHTEST_DELTA
147 shtest_score = self.shtest_accumulator / SHTEST_DELTA;
148 if(shtest_score > 1.2)
149 dprint("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
150 else if(cvar("developer_shtest"))
151 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
153 self.shtest_next = time + SHTEST_DELTA;
154 self.shtest_accumulator = 0;
156 self.shtest_accumulator += frametime;
158 if (clienttype(self) == CLIENTTYPE_BOT)
161 if (self.movetype == MOVETYPE_NONE)
164 if (self.punchangle != '0 0 0')
166 f = vlen(self.punchangle) - 10 * frametime;
168 self.punchangle = normalize(self.punchangle) * f;
170 self.punchangle = '0 0 0';
173 if (self.punchvector != '0 0 0')
175 f = vlen(self.punchvector) - 30 * frametime;
177 self.punchvector = normalize(self.punchvector) * f;
179 self.punchvector = '0 0 0';
186 if(self.runes & RUNE_SPEED)
188 if(self.runes & CURSE_SLOW)
189 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
191 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
193 else if(self.runes & CURSE_SLOW)
195 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
199 if(g_minstagib && (self.items & IT_INVINCIBLE))
201 maxspd_mod = cvar("g_minstagib_speed_moverate");
206 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
209 if(self.flags & FL_NOTARGET)
211 maxspd_mod = cvar("sv_spectator_speed_multiplier");
212 if(!self.spectatorspeed)
213 self.spectatorspeed = maxspd_mod;
214 if(self.impulse && self.impulse <= 12)
216 if(self.lastflags & FL_NOTARGET)
218 if(self.impulse == 10)
219 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
220 else if(self.impulse == 11)
221 self.spectatorspeed = maxspd_mod;
222 else if(self.impulse == 12)
223 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
224 else if(self.impulse >= 1 && self.impulse <= 9)
225 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
226 } // otherwise just clear
230 maxspd_mod = self.spectatorspeed;
233 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
235 if(self.speed != spd)
239 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
240 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
241 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
242 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
244 temps = ftos(sv_accelerate * maxspd_mod);
245 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
248 // if dead, behave differently
255 self.angles_y = self.v_angle_y;
259 if(self.flags & FL_ONGROUND)
264 if(self.waterlevel < 2)
265 if(time >= self.ladder_time)
268 self.nextstep = time + 0.3 + random() * 0.1;
269 trace_dphitq3surfaceflags = 0;
270 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
271 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
273 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
274 GlobalSound(globalsound_metalfall, CHAN_PLAYER, 0);
276 GlobalSound(globalsound_fall, CHAN_PLAYER, 0);
284 if(self.classname == "player")
288 self.flags = self.flags - (self.flags & FL_ONGROUND);
289 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
290 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
291 self.flags = self.flags | FL_ONGROUND;
294 if (self.BUTTON_JUMP)
297 self.flags = self.flags | FL_JUMPRELEASED;
299 if (self.waterlevel == 2)
303 if (self.flags & FL_WATERJUMP )
305 self.velocity_x = self.movedir_x;
306 self.velocity_y = self.movedir_y;
307 if (time > self.teleport_time || self.waterlevel == 0)
309 self.flags = self.flags - (self.flags & FL_WATERJUMP);
310 self.teleport_time = 0;
313 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
315 // noclipping or flying
316 self.flags = self.flags - (self.flags & FL_ONGROUND);
318 self.velocity = self.velocity * (1 - frametime * sv_friction);
319 makevectors(self.v_angle);
320 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
321 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
323 wishdir = normalize(wishvel);
324 wishspeed = vlen(wishvel);
325 if (wishspeed > sv_maxspeed*maxspd_mod)
326 wishspeed = sv_maxspeed*maxspd_mod;
327 if (time >= self.teleport_time)
329 f = wishspeed - (self.velocity * wishdir);
331 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
334 else if (self.waterlevel >= 2)
337 self.flags = self.flags - (self.flags & FL_ONGROUND);
339 makevectors(self.v_angle);
340 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
341 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
342 if (wishvel == '0 0 0')
343 wishvel = '0 0 -60'; // drift towards bottom
345 wishdir = normalize(wishvel);
346 wishspeed = vlen(wishvel);
347 if (wishspeed > sv_maxspeed*maxspd_mod)
348 wishspeed = sv_maxspeed*maxspd_mod;
349 wishspeed = wishspeed * 0.7;
352 self.velocity = self.velocity * (1 - frametime * sv_friction);
354 // water acceleration
355 f = wishspeed - (self.velocity * wishdir);
357 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
359 else if (time < self.ladder_time)
361 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
362 self.flags = self.flags - (self.flags & FL_ONGROUND);
364 self.velocity = self.velocity * (1 - frametime * sv_friction);
365 makevectors(self.v_angle);
366 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
367 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
369 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
371 self.velocity_z = self.velocity_z + sv_gravity * frametime;
372 if (self.ladder_entity.classname == "func_water")
375 if (f > self.ladder_entity.speed)
376 wishvel = wishvel * (self.ladder_entity.speed / f);
378 self.watertype = self.ladder_entity.skin;
379 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
380 if ((self.origin_z + self.view_ofs_z) < f)
382 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
384 else if ((self.origin_z + self.mins_z + 1) < f)
389 self.watertype = CONTENT_EMPTY;
393 wishdir = normalize(wishvel);
394 wishspeed = vlen(wishvel);
395 if (wishspeed > sv_maxspeed)
396 wishspeed = sv_maxspeed;
397 if (time >= self.teleport_time)
399 f = wishspeed - (self.velocity * wishdir);
401 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
404 else if (self.flags & FL_ONGROUND)
407 makevectors(self.v_angle_y * '0 1 0');
408 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
410 if(!(self.lastflags & FL_ONGROUND))
412 if(cvar("speedmeter"))
413 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
414 if(self.lastground < time - 0.3)
415 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
416 if(self.jumppadcount > 1)
417 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
418 self.jumppadcount = 0;
421 if (self.velocity_x || self.velocity_y)
422 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
427 if (f < sv_stopspeed)
428 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
430 f = 1 - frametime * sv_friction;
432 self.velocity = self.velocity * f;
434 self.velocity = '0 0 0';
437 wishdir = normalize(wishvel);
438 wishspeed = vlen(wishvel);
439 if (wishspeed > sv_maxspeed*maxspd_mod)
440 wishspeed = sv_maxspeed*maxspd_mod;
442 wishspeed = wishspeed * 0.5;
443 if (time >= self.teleport_time)
445 f = wishspeed - (self.velocity * wishdir);
447 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
454 maxairspd = sv_maxairspeed*maxspd_mod;
455 airaccel = sv_airaccelerate*maxspd_mod;
459 maxairspd = sv_maxairspeed;
460 airaccel = sv_airaccelerate;
463 makevectors(self.v_angle_y * '0 1 0');
464 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
466 wishdir = normalize(wishvel);
467 wishspeed = vlen(wishvel);
468 if (wishspeed > maxairspd)
469 wishspeed = maxairspd;
471 wishspeed = wishspeed * 0.5;
472 if (time >= self.teleport_time)
474 // NOTE: this does the same as the commented out old code if:
476 // sv_airaccel_sideways_friction 0
481 vel_straight = self.velocity * wishdir;
482 vel_z = self.velocity_z;
483 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
485 f = wishspeed - vel_straight;
487 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
489 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
491 // anti-sideways friction to fix QW-style bunnyhopping
492 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
494 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
497 f = wishspeed;// - (self.velocity * wishdir);
499 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
504 if(self.flags & FL_ONGROUND)
505 self.lastground = time;
507 self.lastflags = self.flags;