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)
239 self.nextstep = time + 0.3 + random() * 0.1;
240 trace_dphitq3surfaceflags = 0;
241 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
242 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
244 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
245 GlobalSound(globalsound_metalfall, CHAN_AUTO, 0);
247 GlobalSound(globalsound_fall, CHAN_AUTO, 0);
251 if(self.classname == "player")
255 self.flags = self.flags - (self.flags & FL_ONGROUND);
256 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
257 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
258 self.flags = self.flags | FL_ONGROUND;
261 if (self.BUTTON_JUMP)
264 self.flags = self.flags | FL_JUMPRELEASED;
266 if (self.waterlevel == 2)
270 if (self.flags & FL_WATERJUMP )
272 self.velocity_x = self.movedir_x;
273 self.velocity_y = self.movedir_y;
274 if (time > self.teleport_time || self.waterlevel == 0)
276 self.flags = self.flags - (self.flags & FL_WATERJUMP);
277 self.teleport_time = 0;
280 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
282 // noclipping or flying
283 self.flags = self.flags - (self.flags & FL_ONGROUND);
285 self.velocity = self.velocity * (1 - frametime * sv_friction);
286 makevectors(self.v_angle);
287 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
288 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
290 wishdir = normalize(wishvel);
291 wishspeed = vlen(wishvel);
292 if (wishspeed > sv_maxspeed*maxspd_mod)
293 wishspeed = sv_maxspeed*maxspd_mod;
294 if (time >= self.teleport_time)
296 f = wishspeed - (self.velocity * wishdir);
298 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
301 else if (self.waterlevel >= 2)
304 self.flags = self.flags - (self.flags & FL_ONGROUND);
306 makevectors(self.v_angle);
307 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
308 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
309 if (wishvel == '0 0 0')
310 wishvel = '0 0 -60'; // drift towards bottom
312 wishdir = normalize(wishvel);
313 wishspeed = vlen(wishvel);
314 if (wishspeed > sv_maxspeed*maxspd_mod)
315 wishspeed = sv_maxspeed*maxspd_mod;
316 wishspeed = wishspeed * 0.7;
319 self.velocity = self.velocity * (1 - frametime * sv_friction);
321 // water acceleration
322 f = wishspeed - (self.velocity * wishdir);
324 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
326 else if (time < self.ladder_time)
328 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
329 self.flags = self.flags - (self.flags & FL_ONGROUND);
331 self.velocity = self.velocity * (1 - frametime * sv_friction);
332 makevectors(self.v_angle);
333 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
334 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
336 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
338 self.velocity_z = self.velocity_z + sv_gravity * frametime;
339 if (self.ladder_entity.classname == "func_water")
342 if (f > self.ladder_entity.speed)
343 wishvel = wishvel * (self.ladder_entity.speed / f);
345 self.watertype = self.ladder_entity.skin;
346 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
347 if ((self.origin_z + self.view_ofs_z) < f)
349 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
351 else if ((self.origin_z + self.mins_z + 1) < f)
356 self.watertype = CONTENT_EMPTY;
360 wishdir = normalize(wishvel);
361 wishspeed = vlen(wishvel);
362 if (wishspeed > sv_maxspeed)
363 wishspeed = sv_maxspeed;
364 if (time >= self.teleport_time)
366 f = wishspeed - (self.velocity * wishdir);
368 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
371 else if (self.flags & FL_ONGROUND)
374 makevectors(self.v_angle_y * '0 1 0');
375 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
377 if(!(self.lastflags & FL_ONGROUND))
379 if(cvar("speedmeter"))
380 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
381 if(self.lastground < time - 0.3)
382 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
383 if(self.jumppadcount > 1)
384 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
385 self.jumppadcount = 0;
388 if (self.velocity_x || self.velocity_y)
389 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
394 if (f < sv_stopspeed)
395 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
397 f = 1 - frametime * sv_friction;
399 self.velocity = self.velocity * f;
401 self.velocity = '0 0 0';
404 wishdir = normalize(wishvel);
405 wishspeed = vlen(wishvel);
406 if (wishspeed > sv_maxspeed*maxspd_mod)
407 wishspeed = sv_maxspeed*maxspd_mod;
409 wishspeed = wishspeed * 0.5;
410 if (time >= self.teleport_time)
412 f = wishspeed - (self.velocity * wishdir);
414 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
421 maxairspd = sv_maxairspeed*maxspd_mod;
422 airaccel = sv_airaccelerate*maxspd_mod;
426 maxairspd = sv_maxairspeed;
427 airaccel = sv_airaccelerate;
430 makevectors(self.v_angle_y * '0 1 0');
431 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
433 wishdir = normalize(wishvel);
434 wishspeed = vlen(wishvel);
435 if (wishspeed > maxairspd)
436 wishspeed = maxairspd;
438 wishspeed = wishspeed * 0.5;
439 if (time >= self.teleport_time)
441 // NOTE: this does the same as the commented out old code if:
443 // sv_airaccel_sideways_friction 0
448 vel_straight = self.velocity * wishdir;
449 vel_z = self.velocity_z;
450 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
452 f = wishspeed - vel_straight;
454 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
456 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
458 // anti-sideways friction to fix QW-style bunnyhopping
459 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
461 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
464 f = wishspeed;// - (self.velocity * wishdir);
466 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
471 if(self.flags & FL_ONGROUND)
472 self.lastground = time;
474 self.lastflags = self.flags;