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))
49 if (!(self.flags & FL_JUMPRELEASED))
52 if(cvar("g_runematch"))
54 if(self.runes & RUNE_SPEED)
56 if(self.runes & CURSE_SLOW)
57 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
59 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
61 else if(self.runes & CURSE_SLOW)
63 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
67 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
69 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
72 self.velocity_z = self.velocity_z + mjumpheight;
73 self.oldvelocity_z = self.velocity_z;
75 self.flags = self.flags - FL_ONGROUND;
76 self.flags = self.flags - FL_JUMPRELEASED;
79 void() CheckWaterJump =
81 local vector start, end;
83 // check for a jump-out-of-water
84 makevectors (self.angles);
86 start_z = start_z + 8;
89 end = start + v_forward*24;
90 traceline (start, end, TRUE, self);
91 if (trace_fraction < 1)
93 start_z = start_z + self.maxs_z - 8;
94 end = start + v_forward*24;
95 self.movedir = trace_plane_normal * -50;
96 traceline (start, end, TRUE, self);
97 if (trace_fraction == 1)
98 { // open at eye level
99 self.flags = self.flags | FL_WATERJUMP;
100 self.velocity_z = 225;
101 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
102 self.teleport_time = time + 2; // safety net
109 void Nixnex_GiveCurrentWeapon();
110 void SV_PlayerPhysics()
112 local vector wishvel, wishdir, v;
113 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score;
116 if(time > self.shtest_next)
118 if(self.shtest_next > 0)
120 // self.shtest_accumulator:
121 // started at time - SHTEST_DELTA
122 // should be at SHTEST_DELTA
123 shtest_score = self.shtest_accumulator / SHTEST_DELTA;
124 if(shtest_score > 1.2)
125 dprint("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
127 self.shtest_next = time + SHTEST_DELTA;
128 self.shtest_accumulator = 0;
130 self.shtest_accumulator += frametime;
132 if (clienttype(self) == CLIENTTYPE_BOT)
135 if (self.movetype == MOVETYPE_NONE)
138 if (self.punchangle != '0 0 0')
140 f = vlen(self.punchangle) - 10 * frametime;
142 self.punchangle = normalize(self.punchangle) * f;
144 self.punchangle = '0 0 0';
147 if (self.punchvector != '0 0 0')
149 f = vlen(self.punchvector) - 30 * frametime;
151 self.punchvector = normalize(self.punchvector) * f;
153 self.punchvector = '0 0 0';
158 if(cvar("g_runematch"))
160 if(self.runes & RUNE_SPEED)
162 if(self.runes & CURSE_SLOW)
163 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
165 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
167 else if(self.runes & CURSE_SLOW)
169 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
173 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
175 maxspd_mod = cvar("g_balance_rune_speed_moverate");
180 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
183 if(self.flags & FL_NOTARGET)
184 maxspd_mod = cvar("sv_spectator_speed_multiplier");
186 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
188 if(self.speed != spd)
192 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
193 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
194 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
195 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
197 temps = ftos(sv_accelerate * maxspd_mod);
198 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
201 // if dead, behave differently
208 self.angles_y = self.v_angle_y;
212 if(self.classname == "player")
217 self.flags = self.flags | FL_JUMPRELEASED;
219 if (self.waterlevel == 2)
223 if (self.flags & FL_WATERJUMP )
225 self.velocity_x = self.movedir_x;
226 self.velocity_y = self.movedir_y;
227 if (time > self.teleport_time || self.waterlevel == 0)
229 self.flags = self.flags - (self.flags & FL_WATERJUMP);
230 self.teleport_time = 0;
233 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
235 // noclipping or flying
236 self.flags = self.flags - (self.flags & FL_ONGROUND);
238 self.velocity = self.velocity * (1 - frametime * sv_friction);
239 makevectors(self.v_angle);
240 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
241 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
243 wishdir = normalize(wishvel);
244 wishspeed = vlen(wishvel);
245 if (wishspeed > sv_maxspeed*maxspd_mod)
246 wishspeed = sv_maxspeed*maxspd_mod;
247 if (time >= self.teleport_time)
249 f = wishspeed - (self.velocity * wishdir);
251 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
254 else if (self.waterlevel >= 2)
257 self.flags = self.flags - (self.flags & FL_ONGROUND);
259 makevectors(self.v_angle);
260 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
261 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
262 if (wishvel == '0 0 0')
263 wishvel = '0 0 -60'; // drift towards bottom
265 wishdir = normalize(wishvel);
266 wishspeed = vlen(wishvel);
267 if (wishspeed > sv_maxspeed*maxspd_mod)
268 wishspeed = sv_maxspeed*maxspd_mod;
269 wishspeed = wishspeed * 0.7;
272 self.velocity = self.velocity * (1 - frametime * sv_friction);
274 // water acceleration
275 f = wishspeed - (self.velocity * wishdir);
277 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
279 else if (time < self.ladder_time)
281 // on a func_ladder or swimming in func_water
282 self.flags = self.flags - (self.flags & FL_ONGROUND);
284 self.velocity = self.velocity * (1 - frametime * sv_friction);
285 makevectors(self.v_angle);
286 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
287 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
289 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
291 self.velocity_z = self.velocity_z + sv_gravity * frametime;
292 if (self.ladder_entity.classname == "func_water")
295 if (f > self.ladder_entity.speed)
296 wishvel = wishvel * (self.ladder_entity.speed / f);
298 self.watertype = self.ladder_entity.skin;
299 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
300 if ((self.origin_z + self.view_ofs_z) < f)
302 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
304 else if ((self.origin_z + self.mins_z + 1) < f)
309 self.watertype = CONTENT_EMPTY;
313 wishdir = normalize(wishvel);
314 wishspeed = vlen(wishvel);
315 if (wishspeed > sv_maxspeed)
316 wishspeed = sv_maxspeed;
317 if (time >= self.teleport_time)
319 f = wishspeed - (self.velocity * wishdir);
321 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
324 else if (self.flags & FL_ONGROUND)
327 makevectors(self.v_angle_y * '0 1 0');
328 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
330 if(!(self.lastflags & FL_ONGROUND))
332 if(cvar("speedmeter"))
333 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
334 if(self.lastground < time - 0.3)
335 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
336 if(self.jumppadcount > 1)
337 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
338 self.jumppadcount = 0;
341 if (self.velocity_x || self.velocity_y)
342 if (!(self.flags & FL_JUMPRELEASED) || !self.button2)
347 if (f < sv_stopspeed)
348 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
350 f = 1 - frametime * sv_friction;
352 self.velocity = self.velocity * f;
354 self.velocity = '0 0 0';
357 wishdir = normalize(wishvel);
358 wishspeed = vlen(wishvel);
359 if (wishspeed > sv_maxspeed*maxspd_mod)
360 wishspeed = sv_maxspeed*maxspd_mod;
362 wishspeed = wishspeed * 0.5;
363 if (time >= self.teleport_time)
365 f = wishspeed - (self.velocity * wishdir);
367 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
374 maxairspd = sv_maxairspeed*maxspd_mod;
375 airaccel = sv_airaccelerate*maxspd_mod;
379 maxairspd = sv_maxairspeed;
380 airaccel = sv_airaccelerate;
383 makevectors(self.v_angle_y * '0 1 0');
384 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
386 wishdir = normalize(wishvel);
387 wishspeed = vlen(wishvel);
388 if (wishspeed > maxairspd)
389 wishspeed = maxairspd;
391 wishspeed = wishspeed * 0.5;
392 if (time >= self.teleport_time)
394 // NOTE: this does the same as the commented out old code if:
396 // sv_airaccel_sideways_friction 0
401 vel_straight = self.velocity * wishdir;
402 vel_z = self.velocity_z;
403 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
405 f = wishspeed - vel_straight;
407 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
409 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
411 // anti-sideways friction to fix QW-style bunnyhopping
412 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
414 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
417 f = wishspeed;// - (self.velocity * wishdir);
419 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
424 if(self.flags & FL_ONGROUND)
425 self.lastground = time;
427 self.lastflags = self.flags;