4 float sv_airaccelerate;
8 float sv_airaccel_sideways_friction;
11 .entity ladder_entity;
13 .float swamp_slowdown;
18 #define SHTEST_DELTA 15
20 .float shtest_accumulator;
26 When you press the jump key
29 void PlayerJump (void)
33 mjumpheight = cvar("sv_jumpvelocity");
34 if (self.waterlevel >= 2)
36 if (self.watertype == CONTENT_WATER)
37 self.velocity_z = 200;
38 else if (self.watertype == CONTENT_SLIME)
47 if (!(self.flags & FL_ONGROUND))
51 if (!(self.flags & FL_JUMPRELEASED))
56 if(self.runes & RUNE_SPEED)
58 if(self.runes & CURSE_SLOW)
59 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
61 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
63 else if(self.runes & CURSE_SLOW)
65 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
69 if(g_minstagib && (self.items & IT_INVINCIBLE))
71 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
74 self.velocity_z = self.velocity_z + mjumpheight;
75 self.oldvelocity_z = self.velocity_z;
77 self.flags = self.flags - FL_ONGROUND;
78 self.flags = self.flags - FL_JUMPRELEASED;
81 player_setanim(self.anim_duckjump, FALSE, TRUE, TRUE);
83 player_setanim(self.anim_jump, FALSE, TRUE, TRUE);
86 PlayerSound(playersound_jump, CHAN_PLAYER, 0);
91 local vector start, end;
93 // check for a jump-out-of-water
94 makevectors (self.angles);
96 start_z = start_z + 8;
99 end = start + v_forward*24;
100 traceline (start, end, TRUE, self);
101 if (trace_fraction < 1)
103 start_z = start_z + self.maxs_z - 8;
104 end = start + v_forward*24;
105 self.movedir = trace_plane_normal * -50;
106 traceline (start, end, TRUE, self);
107 if (trace_fraction == 1)
108 { // open at eye level
109 self.flags = self.flags | FL_WATERJUMP;
110 self.velocity_z = 225;
111 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
112 self.teleport_time = time + 2; // safety net
118 .vector movement_old;
122 void Nixnex_GiveCurrentWeapon();
123 void SV_PlayerPhysics()
125 local vector wishvel, wishdir, v;
126 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
129 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;
130 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
132 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
133 self.parm_idlesince = time;
135 self.buttons_old = buttons;
136 self.movement_old = self.movement;
137 self.v_angle_old = self.v_angle;
139 if(time > self.shtest_next)
141 if(self.shtest_next > 0)
143 // self.shtest_accumulator:
144 // started at time - SHTEST_DELTA
145 // should be at SHTEST_DELTA
146 shtest_score = self.shtest_accumulator / SHTEST_DELTA;
147 if(shtest_score > 1.2)
148 dprint("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
149 else if(cvar("developer_shtest"))
150 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
152 self.shtest_next = time + SHTEST_DELTA;
153 self.shtest_accumulator = 0;
155 self.shtest_accumulator += frametime;
157 if (clienttype(self) == CLIENTTYPE_BOT)
160 if (self.movetype == MOVETYPE_NONE)
163 if (self.punchangle != '0 0 0')
165 f = vlen(self.punchangle) - 10 * frametime;
167 self.punchangle = normalize(self.punchangle) * f;
169 self.punchangle = '0 0 0';
172 if (self.punchvector != '0 0 0')
174 f = vlen(self.punchvector) - 30 * frametime;
176 self.punchvector = normalize(self.punchvector) * f;
178 self.punchvector = '0 0 0';
185 if(self.runes & RUNE_SPEED)
187 if(self.runes & CURSE_SLOW)
188 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
190 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
192 else if(self.runes & CURSE_SLOW)
194 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
198 if(g_minstagib && (self.items & IT_INVINCIBLE))
200 maxspd_mod = cvar("g_minstagib_speed_moverate");
205 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
208 if(self.flags & FL_NOTARGET)
209 maxspd_mod = cvar("sv_spectator_speed_multiplier");
211 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
213 if(self.speed != spd)
217 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
218 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
219 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
220 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
222 temps = ftos(sv_accelerate * maxspd_mod);
223 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
226 // if dead, behave differently
233 self.angles_y = self.v_angle_y;
237 if(self.flags & FL_ONGROUND)
242 if(self.waterlevel < 2)
243 if(time >= self.ladder_time)
246 self.nextstep = time + 0.3 + random() * 0.1;
247 trace_dphitq3surfaceflags = 0;
248 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
249 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
251 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
252 GlobalSound(globalsound_metalfall, CHAN_PLAYER, 0);
254 GlobalSound(globalsound_fall, CHAN_PLAYER, 0);
262 if(self.classname == "player")
266 self.flags = self.flags - (self.flags & FL_ONGROUND);
267 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
268 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
269 self.flags = self.flags | FL_ONGROUND;
272 if (self.BUTTON_JUMP)
275 self.flags = self.flags | FL_JUMPRELEASED;
277 if (self.waterlevel == 2)
281 if (self.flags & FL_WATERJUMP )
283 self.velocity_x = self.movedir_x;
284 self.velocity_y = self.movedir_y;
285 if (time > self.teleport_time || self.waterlevel == 0)
287 self.flags = self.flags - (self.flags & FL_WATERJUMP);
288 self.teleport_time = 0;
291 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
293 // noclipping or flying
294 self.flags = self.flags - (self.flags & FL_ONGROUND);
296 self.velocity = self.velocity * (1 - frametime * sv_friction);
297 makevectors(self.v_angle);
298 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
299 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
301 wishdir = normalize(wishvel);
302 wishspeed = vlen(wishvel);
303 if (wishspeed > sv_maxspeed*maxspd_mod)
304 wishspeed = sv_maxspeed*maxspd_mod;
305 if (time >= self.teleport_time)
307 f = wishspeed - (self.velocity * wishdir);
309 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
312 else if (self.waterlevel >= 2)
315 self.flags = self.flags - (self.flags & FL_ONGROUND);
317 makevectors(self.v_angle);
318 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
319 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
320 if (wishvel == '0 0 0')
321 wishvel = '0 0 -60'; // drift towards bottom
323 wishdir = normalize(wishvel);
324 wishspeed = vlen(wishvel);
325 if (wishspeed > sv_maxspeed*maxspd_mod)
326 wishspeed = sv_maxspeed*maxspd_mod;
327 wishspeed = wishspeed * 0.7;
330 self.velocity = self.velocity * (1 - frametime * sv_friction);
332 // water acceleration
333 f = wishspeed - (self.velocity * wishdir);
335 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
337 else if (time < self.ladder_time)
339 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
340 self.flags = self.flags - (self.flags & FL_ONGROUND);
342 self.velocity = self.velocity * (1 - frametime * sv_friction);
343 makevectors(self.v_angle);
344 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
345 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
347 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
349 self.velocity_z = self.velocity_z + sv_gravity * frametime;
350 if (self.ladder_entity.classname == "func_water")
353 if (f > self.ladder_entity.speed)
354 wishvel = wishvel * (self.ladder_entity.speed / f);
356 self.watertype = self.ladder_entity.skin;
357 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
358 if ((self.origin_z + self.view_ofs_z) < f)
360 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
362 else if ((self.origin_z + self.mins_z + 1) < f)
367 self.watertype = CONTENT_EMPTY;
371 wishdir = normalize(wishvel);
372 wishspeed = vlen(wishvel);
373 if (wishspeed > sv_maxspeed)
374 wishspeed = sv_maxspeed;
375 if (time >= self.teleport_time)
377 f = wishspeed - (self.velocity * wishdir);
379 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
382 else if (self.flags & FL_ONGROUND)
385 makevectors(self.v_angle_y * '0 1 0');
386 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
388 if(!(self.lastflags & FL_ONGROUND))
390 if(cvar("speedmeter"))
391 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
392 if(self.lastground < time - 0.3)
393 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
394 if(self.jumppadcount > 1)
395 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
396 self.jumppadcount = 0;
399 if (self.velocity_x || self.velocity_y)
400 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
405 if (f < sv_stopspeed)
406 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
408 f = 1 - frametime * sv_friction;
410 self.velocity = self.velocity * f;
412 self.velocity = '0 0 0';
415 wishdir = normalize(wishvel);
416 wishspeed = vlen(wishvel);
417 if (wishspeed > sv_maxspeed*maxspd_mod)
418 wishspeed = sv_maxspeed*maxspd_mod;
420 wishspeed = wishspeed * 0.5;
421 if (time >= self.teleport_time)
423 f = wishspeed - (self.velocity * wishdir);
425 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
432 maxairspd = sv_maxairspeed*maxspd_mod;
433 airaccel = sv_airaccelerate*maxspd_mod;
437 maxairspd = sv_maxairspeed;
438 airaccel = sv_airaccelerate;
441 makevectors(self.v_angle_y * '0 1 0');
442 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
444 wishdir = normalize(wishvel);
445 wishspeed = vlen(wishvel);
446 if (wishspeed > maxairspd)
447 wishspeed = maxairspd;
449 wishspeed = wishspeed * 0.5;
450 if (time >= self.teleport_time)
452 // NOTE: this does the same as the commented out old code if:
454 // sv_airaccel_sideways_friction 0
459 vel_straight = self.velocity * wishdir;
460 vel_z = self.velocity_z;
461 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
463 f = wishspeed - vel_straight;
465 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
467 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
469 // anti-sideways friction to fix QW-style bunnyhopping
470 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
472 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
475 f = wishspeed;// - (self.velocity * wishdir);
477 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
482 if(self.flags & FL_ONGROUND)
483 self.lastground = time;
485 self.lastflags = self.flags;