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 10
20 #define SHTEST_THRESHOLD 1.1
22 .float shtest_accumulator;
28 When you press the jump key
31 void PlayerJump (void)
35 mjumpheight = cvar("sv_jumpvelocity");
36 if (self.waterlevel >= 2)
38 if (self.watertype == CONTENT_WATER)
39 self.velocity_z = 200;
40 else if (self.watertype == CONTENT_SLIME)
49 if (!(self.flags & FL_ONGROUND))
53 if (!(self.flags & FL_JUMPRELEASED))
58 if(self.runes & RUNE_SPEED)
60 if(self.runes & CURSE_SLOW)
61 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
63 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
65 else if(self.runes & CURSE_SLOW)
67 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
71 if(g_minstagib && (self.items & IT_INVINCIBLE))
73 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
76 self.velocity_z = self.velocity_z + mjumpheight;
77 self.oldvelocity_z = self.velocity_z;
79 self.flags = self.flags - FL_ONGROUND;
80 self.flags = self.flags - FL_JUMPRELEASED;
83 player_setanim(self.anim_duckjump, FALSE, TRUE, TRUE);
85 player_setanim(self.anim_jump, FALSE, TRUE, TRUE);
88 PlayerSound(playersound_jump, CHAN_PLAYER, 0);
93 local vector start, end;
95 // check for a jump-out-of-water
96 makevectors (self.angles);
98 start_z = start_z + 8;
100 normalize(v_forward);
101 end = start + v_forward*24;
102 traceline (start, end, TRUE, self);
103 if (trace_fraction < 1)
105 start_z = start_z + self.maxs_z - 8;
106 end = start + v_forward*24;
107 self.movedir = trace_plane_normal * -50;
108 traceline (start, end, TRUE, self);
109 if (trace_fraction == 1)
110 { // open at eye level
111 self.flags = self.flags | FL_WATERJUMP;
112 self.velocity_z = 225;
113 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
114 self.teleport_time = time + 2; // safety net
120 .vector movement_old;
124 void Nixnex_GiveCurrentWeapon();
125 void SV_PlayerPhysics()
127 local vector wishvel, wishdir, v;
128 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
131 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;
132 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
134 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
135 self.parm_idlesince = time;
137 self.buttons_old = buttons;
138 self.movement_old = self.movement;
139 self.v_angle_old = self.v_angle;
141 if(time > self.shtest_next)
143 if(self.shtest_next > 0)
145 // self.shtest_accumulator:
146 // started at time - SHTEST_DELTA
147 // should be at SHTEST_DELTA
148 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
149 if(shtest_score > SHTEST_THRESHOLD)
150 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
151 else if(cvar("developer_shtest"))
152 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
154 self.shtest_next = time + SHTEST_DELTA;
155 self.shtest_accumulator = 0;
157 self.shtest_accumulator += frametime;
159 if (clienttype(self) == CLIENTTYPE_BOT)
162 if (self.movetype == MOVETYPE_NONE)
165 if (self.punchangle != '0 0 0')
167 f = vlen(self.punchangle) - 10 * frametime;
169 self.punchangle = normalize(self.punchangle) * f;
171 self.punchangle = '0 0 0';
174 if (self.punchvector != '0 0 0')
176 f = vlen(self.punchvector) - 30 * frametime;
178 self.punchvector = normalize(self.punchvector) * f;
180 self.punchvector = '0 0 0';
187 if(self.runes & RUNE_SPEED)
189 if(self.runes & CURSE_SLOW)
190 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
192 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
194 else if(self.runes & CURSE_SLOW)
196 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
200 if(g_minstagib && (self.items & IT_INVINCIBLE))
202 maxspd_mod = cvar("g_minstagib_speed_moverate");
207 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
210 if(self.flags & FL_NOTARGET)
212 maxspd_mod = cvar("sv_spectator_speed_multiplier");
213 if(!self.spectatorspeed)
214 self.spectatorspeed = maxspd_mod;
215 if(self.impulse && self.impulse <= 12)
217 if(self.lastflags & FL_NOTARGET)
219 if(self.impulse == 10)
220 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
221 else if(self.impulse == 11)
222 self.spectatorspeed = maxspd_mod;
223 else if(self.impulse == 12)
224 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
225 else if(self.impulse >= 1 && self.impulse <= 9)
226 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
227 } // otherwise just clear
231 maxspd_mod = self.spectatorspeed;
234 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
236 if(self.speed != spd)
240 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
241 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
242 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
243 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
245 temps = ftos(sv_accelerate * maxspd_mod);
246 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
249 // if dead, behave differently
256 self.angles_y = self.v_angle_y;
260 if(self.flags & FL_ONGROUND)
265 if(self.waterlevel < 2)
266 if(time >= self.ladder_time)
269 self.nextstep = time + 0.3 + random() * 0.1;
270 trace_dphitq3surfaceflags = 0;
271 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
272 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
274 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
275 GlobalSound(globalsound_metalfall, CHAN_PLAYER, 0);
277 GlobalSound(globalsound_fall, CHAN_PLAYER, 0);
285 if(self.classname == "player")
289 self.flags = self.flags - (self.flags & FL_ONGROUND);
290 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
291 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
292 self.flags = self.flags | FL_ONGROUND;
295 if (self.BUTTON_JUMP)
298 self.flags = self.flags | FL_JUMPRELEASED;
300 if (self.waterlevel == 2)
304 if (self.flags & FL_WATERJUMP )
306 self.velocity_x = self.movedir_x;
307 self.velocity_y = self.movedir_y;
308 if (time > self.teleport_time || self.waterlevel == 0)
310 self.flags = self.flags - (self.flags & FL_WATERJUMP);
311 self.teleport_time = 0;
314 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
316 // noclipping or flying
317 self.flags = self.flags - (self.flags & FL_ONGROUND);
319 self.velocity = self.velocity * (1 - frametime * sv_friction);
320 makevectors(self.v_angle);
321 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
322 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
324 wishdir = normalize(wishvel);
325 wishspeed = vlen(wishvel);
326 if (wishspeed > sv_maxspeed*maxspd_mod)
327 wishspeed = sv_maxspeed*maxspd_mod;
328 if (time >= self.teleport_time)
330 f = wishspeed - (self.velocity * wishdir);
332 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
335 else if (self.waterlevel >= 2)
338 self.flags = self.flags - (self.flags & FL_ONGROUND);
340 makevectors(self.v_angle);
341 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
342 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
343 if (wishvel == '0 0 0')
344 wishvel = '0 0 -60'; // drift towards bottom
346 wishdir = normalize(wishvel);
347 wishspeed = vlen(wishvel);
348 if (wishspeed > sv_maxspeed*maxspd_mod)
349 wishspeed = sv_maxspeed*maxspd_mod;
350 wishspeed = wishspeed * 0.7;
353 self.velocity = self.velocity * (1 - frametime * sv_friction);
355 // water acceleration
356 f = wishspeed - (self.velocity * wishdir);
358 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
360 else if (time < self.ladder_time)
362 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
363 self.flags = self.flags - (self.flags & FL_ONGROUND);
365 self.velocity = self.velocity * (1 - frametime * sv_friction);
366 makevectors(self.v_angle);
367 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
368 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
370 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
372 self.velocity_z = self.velocity_z + sv_gravity * frametime;
373 if (self.ladder_entity.classname == "func_water")
376 if (f > self.ladder_entity.speed)
377 wishvel = wishvel * (self.ladder_entity.speed / f);
379 self.watertype = self.ladder_entity.skin;
380 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
381 if ((self.origin_z + self.view_ofs_z) < f)
383 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
385 else if ((self.origin_z + self.mins_z + 1) < f)
390 self.watertype = CONTENT_EMPTY;
394 wishdir = normalize(wishvel);
395 wishspeed = vlen(wishvel);
396 if (wishspeed > sv_maxspeed)
397 wishspeed = sv_maxspeed;
398 if (time >= self.teleport_time)
400 f = wishspeed - (self.velocity * wishdir);
402 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
405 else if (self.flags & FL_ONGROUND)
408 makevectors(self.v_angle_y * '0 1 0');
409 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
411 if(!(self.lastflags & FL_ONGROUND))
413 if(cvar("speedmeter"))
414 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
415 if(self.lastground < time - 0.3)
416 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
417 if(self.jumppadcount > 1)
418 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
419 self.jumppadcount = 0;
422 if (self.velocity_x || self.velocity_y)
423 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
428 if (f < sv_stopspeed)
429 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
431 f = 1 - frametime * sv_friction;
433 self.velocity = self.velocity * f;
435 self.velocity = '0 0 0';
438 wishdir = normalize(wishvel);
439 wishspeed = vlen(wishvel);
440 if (wishspeed > sv_maxspeed*maxspd_mod)
441 wishspeed = sv_maxspeed*maxspd_mod;
443 wishspeed = wishspeed * 0.5;
444 if (time >= self.teleport_time)
446 f = wishspeed - (self.velocity * wishdir);
448 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
455 maxairspd = sv_maxairspeed*maxspd_mod;
456 airaccel = sv_airaccelerate*maxspd_mod;
460 maxairspd = sv_maxairspeed;
461 airaccel = sv_airaccelerate;
464 makevectors(self.v_angle_y * '0 1 0');
465 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
467 wishdir = normalize(wishvel);
468 wishspeed = vlen(wishvel);
469 if (wishspeed > maxairspd)
470 wishspeed = maxairspd;
472 wishspeed = wishspeed * 0.5;
473 if (time >= self.teleport_time)
475 // NOTE: this does the same as the commented out old code if:
477 // sv_airaccel_sideways_friction 0
482 vel_straight = self.velocity * wishdir;
483 vel_z = self.velocity_z;
484 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
486 f = wishspeed - vel_straight;
488 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
490 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
492 // anti-sideways friction to fix QW-style bunnyhopping
493 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
495 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
498 f = wishspeed;// - (self.velocity * wishdir);
500 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
505 if(self.flags & FL_ONGROUND)
506 self.lastground = time;
508 self.lastflags = self.flags;