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))
50 if (!(self.flags & FL_JUMPRELEASED))
55 if(self.runes & RUNE_SPEED)
57 if(self.runes & CURSE_SLOW)
58 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
60 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
62 else if(self.runes & CURSE_SLOW)
64 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
68 if(g_minstagib && (self.items & IT_INVINCIBLE))
70 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
73 self.velocity_z = self.velocity_z + mjumpheight;
74 self.oldvelocity_z = self.velocity_z;
76 self.flags = self.flags - FL_ONGROUND;
77 self.flags = self.flags - FL_JUMPRELEASED;
80 player_setanim(self.anim_duckjump, FALSE, TRUE, TRUE);
82 player_setanim(self.anim_jump, FALSE, TRUE, TRUE);
85 PlayerSound(playersound_jump, CHAN_AUTO, 0);
90 local vector start, end;
92 // check for a jump-out-of-water
93 makevectors (self.angles);
95 start_z = start_z + 8;
98 end = start + v_forward*24;
99 traceline (start, end, TRUE, self);
100 if (trace_fraction < 1)
102 start_z = start_z + self.maxs_z - 8;
103 end = start + v_forward*24;
104 self.movedir = trace_plane_normal * -50;
105 traceline (start, end, TRUE, self);
106 if (trace_fraction == 1)
107 { // open at eye level
108 self.flags = self.flags | FL_WATERJUMP;
109 self.velocity_z = 225;
110 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
111 self.teleport_time = time + 2; // safety net
117 .vector movement_old;
121 void Nixnex_GiveCurrentWeapon();
122 void SV_PlayerPhysics()
124 local vector wishvel, wishdir, v;
125 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
128 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;
129 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
131 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
132 self.parm_idlesince = time;
134 self.buttons_old = buttons;
135 self.movement_old = self.movement;
136 self.v_angle_old = self.v_angle;
138 if(time > self.shtest_next)
140 if(self.shtest_next > 0)
142 // self.shtest_accumulator:
143 // started at time - SHTEST_DELTA
144 // should be at SHTEST_DELTA
145 shtest_score = self.shtest_accumulator / SHTEST_DELTA;
146 if(shtest_score > 1.2)
147 dprint("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
148 else if(cvar("developer_shtest"))
149 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
151 self.shtest_next = time + SHTEST_DELTA;
152 self.shtest_accumulator = 0;
154 self.shtest_accumulator += frametime;
156 if (clienttype(self) == CLIENTTYPE_BOT)
159 if (self.movetype == MOVETYPE_NONE)
162 if (self.punchangle != '0 0 0')
164 f = vlen(self.punchangle) - 10 * frametime;
166 self.punchangle = normalize(self.punchangle) * f;
168 self.punchangle = '0 0 0';
171 if (self.punchvector != '0 0 0')
173 f = vlen(self.punchvector) - 30 * frametime;
175 self.punchvector = normalize(self.punchvector) * f;
177 self.punchvector = '0 0 0';
184 if(self.runes & RUNE_SPEED)
186 if(self.runes & CURSE_SLOW)
187 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
189 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
191 else if(self.runes & CURSE_SLOW)
193 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
197 if(g_minstagib && (self.items & IT_INVINCIBLE))
199 maxspd_mod = cvar("g_minstagib_speed_moverate");
204 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
207 if(self.flags & FL_NOTARGET)
208 maxspd_mod = cvar("sv_spectator_speed_multiplier");
210 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
212 if(self.speed != spd)
216 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
217 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
218 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
219 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
221 temps = ftos(sv_accelerate * maxspd_mod);
222 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
225 // if dead, behave differently
232 self.angles_y = self.v_angle_y;
236 if(self.flags & FL_ONGROUND)
237 if not(self.lastflags & FL_ONGROUND)
238 if(self.waterlevel < 2)
239 if(time >= self.ladder_time)
242 self.nextstep = time + 0.3 + random() * 0.1;
243 trace_dphitq3surfaceflags = 0;
244 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
245 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
247 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
248 GlobalSound(globalsound_metalfall, CHAN_AUTO, 0);
250 GlobalSound(globalsound_fall, CHAN_AUTO, 0);
254 if(self.classname == "player")
258 self.flags = self.flags - (self.flags & FL_ONGROUND);
259 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
260 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
261 self.flags = self.flags | FL_ONGROUND;
264 if (self.BUTTON_JUMP)
267 self.flags = self.flags | FL_JUMPRELEASED;
269 if (self.waterlevel == 2)
273 if (self.flags & FL_WATERJUMP )
275 self.velocity_x = self.movedir_x;
276 self.velocity_y = self.movedir_y;
277 if (time > self.teleport_time || self.waterlevel == 0)
279 self.flags = self.flags - (self.flags & FL_WATERJUMP);
280 self.teleport_time = 0;
283 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
285 // noclipping or flying
286 self.flags = self.flags - (self.flags & FL_ONGROUND);
288 self.velocity = self.velocity * (1 - frametime * sv_friction);
289 makevectors(self.v_angle);
290 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
291 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
293 wishdir = normalize(wishvel);
294 wishspeed = vlen(wishvel);
295 if (wishspeed > sv_maxspeed*maxspd_mod)
296 wishspeed = sv_maxspeed*maxspd_mod;
297 if (time >= self.teleport_time)
299 f = wishspeed - (self.velocity * wishdir);
301 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
304 else if (self.waterlevel >= 2)
307 self.flags = self.flags - (self.flags & FL_ONGROUND);
309 makevectors(self.v_angle);
310 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
311 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
312 if (wishvel == '0 0 0')
313 wishvel = '0 0 -60'; // drift towards bottom
315 wishdir = normalize(wishvel);
316 wishspeed = vlen(wishvel);
317 if (wishspeed > sv_maxspeed*maxspd_mod)
318 wishspeed = sv_maxspeed*maxspd_mod;
319 wishspeed = wishspeed * 0.7;
322 self.velocity = self.velocity * (1 - frametime * sv_friction);
324 // water acceleration
325 f = wishspeed - (self.velocity * wishdir);
327 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
329 else if (time < self.ladder_time)
331 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
332 self.flags = self.flags - (self.flags & FL_ONGROUND);
334 self.velocity = self.velocity * (1 - frametime * sv_friction);
335 makevectors(self.v_angle);
336 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
337 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
339 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
341 self.velocity_z = self.velocity_z + sv_gravity * frametime;
342 if (self.ladder_entity.classname == "func_water")
345 if (f > self.ladder_entity.speed)
346 wishvel = wishvel * (self.ladder_entity.speed / f);
348 self.watertype = self.ladder_entity.skin;
349 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
350 if ((self.origin_z + self.view_ofs_z) < f)
352 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
354 else if ((self.origin_z + self.mins_z + 1) < f)
359 self.watertype = CONTENT_EMPTY;
363 wishdir = normalize(wishvel);
364 wishspeed = vlen(wishvel);
365 if (wishspeed > sv_maxspeed)
366 wishspeed = sv_maxspeed;
367 if (time >= self.teleport_time)
369 f = wishspeed - (self.velocity * wishdir);
371 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
374 else if (self.flags & FL_ONGROUND)
377 makevectors(self.v_angle_y * '0 1 0');
378 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
380 if(!(self.lastflags & FL_ONGROUND))
382 if(cvar("speedmeter"))
383 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
384 if(self.lastground < time - 0.3)
385 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
386 if(self.jumppadcount > 1)
387 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
388 self.jumppadcount = 0;
391 if (self.velocity_x || self.velocity_y)
392 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
397 if (f < sv_stopspeed)
398 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
400 f = 1 - frametime * sv_friction;
402 self.velocity = self.velocity * f;
404 self.velocity = '0 0 0';
407 wishdir = normalize(wishvel);
408 wishspeed = vlen(wishvel);
409 if (wishspeed > sv_maxspeed*maxspd_mod)
410 wishspeed = sv_maxspeed*maxspd_mod;
412 wishspeed = wishspeed * 0.5;
413 if (time >= self.teleport_time)
415 f = wishspeed - (self.velocity * wishdir);
417 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
424 maxairspd = sv_maxairspeed*maxspd_mod;
425 airaccel = sv_airaccelerate*maxspd_mod;
429 maxairspd = sv_maxairspeed;
430 airaccel = sv_airaccelerate;
433 makevectors(self.v_angle_y * '0 1 0');
434 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
436 wishdir = normalize(wishvel);
437 wishspeed = vlen(wishvel);
438 if (wishspeed > maxairspd)
439 wishspeed = maxairspd;
441 wishspeed = wishspeed * 0.5;
442 if (time >= self.teleport_time)
444 // NOTE: this does the same as the commented out old code if:
446 // sv_airaccel_sideways_friction 0
451 vel_straight = self.velocity * wishdir;
452 vel_z = self.velocity_z;
453 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
455 f = wishspeed - vel_straight;
457 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
459 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
461 // anti-sideways friction to fix QW-style bunnyhopping
462 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
464 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
467 f = wishspeed;// - (self.velocity * wishdir);
469 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
474 if(self.flags & FL_ONGROUND)
475 self.lastground = time;
477 self.lastflags = self.flags;