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 >= WATERLEVEL_SWIMMING)
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))
56 if(self.health <= g_bloodloss)
61 if(self.runes & RUNE_SPEED)
63 if(self.runes & CURSE_SLOW)
64 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
66 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
68 else if(self.runes & CURSE_SLOW)
70 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
74 if(g_minstagib && (self.items & IT_INVINCIBLE))
76 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
79 self.velocity_z = self.velocity_z + mjumpheight;
80 self.oldvelocity_z = self.velocity_z;
82 self.flags &~= FL_ONGROUND;
83 self.flags &~= FL_JUMPRELEASED;
86 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
88 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
91 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
96 local vector start, end;
98 // check for a jump-out-of-water
99 makevectors (self.angles);
101 start_z = start_z + 8;
103 normalize(v_forward);
104 end = start + v_forward*24;
105 traceline (start, end, TRUE, self);
106 if (trace_fraction < 1)
108 start_z = start_z + self.maxs_z - 8;
109 end = start + v_forward*24;
110 self.movedir = trace_plane_normal * -50;
111 traceline (start, end, TRUE, self);
112 if (trace_fraction == 1)
113 { // open at eye level
114 self.flags |= FL_WATERJUMP;
115 self.velocity_z = 225;
116 self.flags &~= FL_JUMPRELEASED;
117 self.teleport_time = time + 2; // safety net
123 float racecar_angle(float forward, float down)
125 float ret, angle_mult;
133 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
135 angle_mult = forward / (800 + forward);
138 return ret * angle_mult + 360 * (1 - angle_mult);
140 return ret * angle_mult;
143 void RaceCarPhysics()
145 // using this move type for "big rigs"
146 // the engine does not push the entity!
148 float accel, steer, f;
149 vector angles_save, rigvel;
151 angles_save = self.angles;
152 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
153 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
155 if(g_bugrigs_reverse_speeding)
159 // back accel is DIGITAL
160 // to prevent speedhack
170 makevectors(self.angles); // new forward direction!
172 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
174 float myspeed, upspeed, steerfactor, accelfactor;
176 myspeed = self.velocity * v_forward;
177 upspeed = self.velocity * v_up;
179 // responsiveness factor for steering and acceleration
180 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
181 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
183 if(myspeed < 0 && g_bugrigs_reverse_spinning)
184 steerfactor = -myspeed * g_bugrigs_steer;
186 steerfactor = -myspeed * f * g_bugrigs_steer;
188 if(myspeed < 0 && g_bugrigs_reverse_speeding)
189 accelfactor = g_bugrigs_accel;
191 accelfactor = f * g_bugrigs_accel;
192 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
198 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
202 if(!g_bugrigs_reverse_speeding)
203 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
210 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
214 if(g_bugrigs_reverse_stopping)
217 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
220 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
221 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
223 self.angles_y += steer * frametime * steerfactor; // apply steering
224 makevectors(self.angles); // new forward direction!
226 myspeed += accel * accelfactor * frametime;
228 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
232 myspeed = vlen(self.velocity);
234 // responsiveness factor for steering and acceleration
235 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
236 steerfactor = -myspeed * f;
237 self.angles_y += steer * frametime * steerfactor; // apply steering
239 rigvel = self.velocity;
240 makevectors(self.angles); // new forward direction!
243 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
244 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
245 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
246 //MAXIMA: solve(total_acceleration(v) = 0, v);
248 if(g_bugrigs_planar_movement)
250 vector rigvel_xy, neworigin, up;
253 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
257 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
260 mt = MOVE_NOMONSTERS;
262 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
263 up = trace_endpos - self.origin;
265 // BUG RIGS: align the move to the surface instead of doing collision testing
267 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
270 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
272 if(trace_fraction < 0.5)
275 neworigin = self.origin;
278 neworigin = trace_endpos;
280 if(trace_fraction < 1)
282 // now set angles_x so that the car points parallel to the surface
283 self.angles = vectoangles(
284 '1 0 0' * v_forward_x * trace_plane_normal_z
286 '0 1 0' * v_forward_y * trace_plane_normal_z
288 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
290 self.flags |= FL_ONGROUND;
294 // now set angles_x so that the car points forward, but is tilted in velocity direction
295 self.flags &~= FL_ONGROUND;
298 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
299 self.movetype = MOVETYPE_NOCLIP;
303 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
304 self.velocity = rigvel;
305 self.movetype = MOVETYPE_FLY;
309 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
310 if(trace_fraction != 1)
312 self.angles = vectoangles2(
313 '1 0 0' * v_forward_x * trace_plane_normal_z
315 '0 1 0' * v_forward_y * trace_plane_normal_z
317 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
325 vel_local_x = v_forward * self.velocity;
326 vel_local_y = v_right * self.velocity;
327 vel_local_z = v_up * self.velocity;
329 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
330 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
334 vector vf1, vu1, smoothangles;
335 makevectors(self.angles);
336 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
341 makevectors(angles_save);
342 vf1 = vf1 + v_forward * (1 - f);
343 vu1 = vu1 + v_up * (1 - f);
344 smoothangles = vectoangles2(vf1, vu1);
345 self.angles_x = -smoothangles_x;
346 self.angles_z = smoothangles_z;
349 .vector movement_old;
352 .string lastclassname;
354 void Nixnex_GiveCurrentWeapon();
355 void SV_PlayerPhysics()
357 local vector wishvel, wishdir, v;
358 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
362 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;
363 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
365 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
366 self.parm_idlesince = time;
368 buttons_prev = self.buttons_old;
369 self.buttons_old = buttons;
370 self.movement_old = self.movement;
371 self.v_angle_old = self.v_angle;
373 if(time < self.nickspamtime)
374 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
376 // slight annoyance for nick change scripts
377 self.movement = -1 * self.movement;
378 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
380 if(self.nickspamcount >= cvar("g_nick_flood_penalty_red")) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
382 self.angles_x = random() * 360;
383 self.angles_y = random() * 360;
384 // at least I'm not forcing retardedview by also assigning to angles_z
389 if(time > self.shtest_next)
391 if(self.shtest_next > 0)
393 // self.shtest_accumulator:
394 // started at time - SHTEST_DELTA
395 // should be at SHTEST_DELTA
396 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
397 if(shtest_score > SHTEST_THRESHOLD)
398 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
399 else if(cvar("developer_shtest"))
400 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
402 self.shtest_next = time + SHTEST_DELTA;
403 self.shtest_accumulator = 0;
405 self.shtest_accumulator += frametime;
407 if (clienttype(self) == CLIENTTYPE_BOT)
410 self.items &~= IT_USING_JETPACK;
412 if (self.movetype == MOVETYPE_NONE && self.disableclientprediction != 2)
415 if (self.punchangle != '0 0 0')
417 f = vlen(self.punchangle) - 10 * frametime;
419 self.punchangle = normalize(self.punchangle) * f;
421 self.punchangle = '0 0 0';
424 if (self.punchvector != '0 0 0')
426 f = vlen(self.punchvector) - 30 * frametime;
428 self.punchvector = normalize(self.punchvector) * f;
430 self.punchvector = '0 0 0';
437 if(self.runes & RUNE_SPEED)
439 if(self.runes & CURSE_SLOW)
440 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
442 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
444 else if(self.runes & CURSE_SLOW)
446 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
450 if(g_minstagib && (self.items & IT_INVINCIBLE))
452 maxspd_mod = cvar("g_minstagib_speed_moverate");
455 if(g_nexball && self.ballcarried)
457 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
462 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
465 if(self.classname != "player")
467 maxspd_mod = cvar("sv_spectator_speed_multiplier");
468 if(!self.spectatorspeed)
469 self.spectatorspeed = maxspd_mod;
470 if(self.impulse && self.impulse <= 19)
472 if(self.lastclassname != "player")
474 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
475 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
476 else if(self.impulse == 11)
477 self.spectatorspeed = maxspd_mod;
478 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
479 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
480 else if(self.impulse >= 1 && self.impulse <= 9)
481 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
482 } // otherwise just clear
485 maxspd_mod = self.spectatorspeed;
488 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
490 if(self.speed != spd)
494 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
495 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
496 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
497 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
499 temps = ftos(sv_accelerate * maxspd_mod);
500 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
503 // if dead, behave differently
507 if (!self.fixangle && !g_bugrigs)
510 self.angles_y = self.v_angle_y;
514 if(self.flags & FL_ONGROUND)
519 if(self.waterlevel < WATERLEVEL_SWIMMING)
520 if(time >= self.ladder_time)
523 self.nextstep = time + 0.3 + random() * 0.1;
524 trace_dphitq3surfaceflags = 0;
525 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
526 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
528 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
529 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
531 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
539 if(self.classname == "player")
543 self.flags &~= FL_ONGROUND;
544 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
545 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
546 self.flags |= FL_ONGROUND;
549 if (self.BUTTON_JUMP)
552 self.flags |= FL_JUMPRELEASED;
554 if (self.waterlevel == WATERLEVEL_SWIMMING)
558 if (self.flags & FL_WATERJUMP )
560 self.velocity_x = self.movedir_x;
561 self.velocity_y = self.movedir_y;
562 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
564 self.flags &~= FL_WATERJUMP;
565 self.teleport_time = 0;
568 else if (g_bugrigs && self.classname == "player")
572 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
574 // noclipping or flying
575 self.flags &~= FL_ONGROUND;
577 self.velocity = self.velocity * (1 - frametime * sv_friction);
578 makevectors(self.v_angle);
579 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
580 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
582 wishdir = normalize(wishvel);
583 wishspeed = vlen(wishvel);
584 if (wishspeed > sv_maxspeed*maxspd_mod)
585 wishspeed = sv_maxspeed*maxspd_mod;
586 if (time >= self.teleport_time)
588 f = wishspeed - (self.velocity * wishdir);
590 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
593 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
596 self.flags &~= FL_ONGROUND;
598 makevectors(self.v_angle);
599 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
600 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
601 if (wishvel == '0 0 0')
602 wishvel = '0 0 -60'; // drift towards bottom
604 wishdir = normalize(wishvel);
605 wishspeed = vlen(wishvel);
606 if (wishspeed > sv_maxspeed*maxspd_mod)
607 wishspeed = sv_maxspeed*maxspd_mod;
608 wishspeed = wishspeed * 0.7;
611 self.velocity = self.velocity * (1 - frametime * sv_friction);
613 // water acceleration
614 f = wishspeed - (self.velocity * wishdir);
616 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
618 else if (time < self.ladder_time)
620 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
621 self.flags &~= FL_ONGROUND;
623 self.velocity = self.velocity * (1 - frametime * sv_friction);
624 makevectors(self.v_angle);
625 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
626 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
628 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
630 self.velocity_z = self.velocity_z + sv_gravity * frametime;
631 if (self.ladder_entity.classname == "func_water")
634 if (f > self.ladder_entity.speed)
635 wishvel = wishvel * (self.ladder_entity.speed / f);
637 self.watertype = self.ladder_entity.skin;
638 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
639 if ((self.origin_z + self.view_ofs_z) < f)
640 self.waterlevel = WATERLEVEL_SUBMERGED;
641 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
642 self.waterlevel = WATERLEVEL_SWIMMING;
643 else if ((self.origin_z + self.mins_z + 1) < f)
644 self.waterlevel = WATERLEVEL_WETFEET;
647 self.waterlevel = WATERLEVEL_NONE;
648 self.watertype = CONTENT_EMPTY;
652 wishdir = normalize(wishvel);
653 wishspeed = vlen(wishvel);
654 if (wishspeed > sv_maxspeed)
655 wishspeed = sv_maxspeed;
656 if (time >= self.teleport_time)
658 f = wishspeed - (self.velocity * wishdir);
660 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
663 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
665 //makevectors(self.v_angle_y * '0 1 0');
666 makevectors(self.v_angle);
667 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
668 // add remaining speed as Z component
669 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
671 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
672 // add the unused velocity as up component
675 // if(self.BUTTON_JUMP)
676 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
678 // it is now normalized, so...
679 float a_side, a_up, a_add, a_diff;
680 a_side = cvar("g_jetpack_acceleration_side");
681 a_up = cvar("g_jetpack_acceleration_up");
682 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
691 //////////////////////////////////////////////////////////////////////////////////////
692 // finding the maximum over all vectors of above form
693 // with wishvel having an absolute value of 1
694 //////////////////////////////////////////////////////////////////////////////////////
695 // we're finding the maximum over
696 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
697 // for z in the range from -1 to 1
698 //////////////////////////////////////////////////////////////////////////////////////
699 // maximum is EITHER attained at the single extreme point:
700 a_diff = a_side * a_side - a_up * a_up;
703 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
704 if(f > -1 && f < 1) // can it be attained?
706 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
710 // OR attained at z = 1:
711 f = (a_up + a_add) * (a_up + a_add);
717 // OR attained at z = -1:
718 f = (a_up - a_add) * (a_up - a_add);
725 //////////////////////////////////////////////////////////////////////////////////////
727 //print("best possible acceleration: ", ftos(best), "\n");
730 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
731 if(wishvel_z - sv_gravity > 0)
732 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
734 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
737 fvel = vlen(wishvel);
740 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
742 fvel = min(1, vlen(wishvel) / best);
743 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
744 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
748 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
750 if (f > 0 && wishvel != '0 0 0')
752 self.velocity = self.velocity + wishvel * f * frametime;
753 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
754 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
755 self.flags &~= FL_ONGROUND;
756 self.items |= IT_USING_JETPACK;
758 // jetpack also inhibits health regeneration, but only for 1 second
759 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
762 else if (self.flags & FL_ONGROUND)
764 // we get here if we ran out of ammo
765 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
766 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
769 makevectors(self.v_angle_y * '0 1 0');
770 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
772 if(!(self.lastflags & FL_ONGROUND))
774 if(cvar("speedmeter"))
775 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
776 if(self.lastground < time - 0.3)
777 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
778 if(self.jumppadcount > 1)
779 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
780 self.jumppadcount = 0;
783 if (self.velocity_x || self.velocity_y)
784 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
789 if (f < sv_stopspeed)
790 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
792 f = 1 - frametime * sv_friction;
794 self.velocity = self.velocity * f;
796 self.velocity = '0 0 0';
799 wishdir = normalize(wishvel);
800 wishspeed = vlen(wishvel);
801 if (wishspeed > sv_maxspeed*maxspd_mod)
802 wishspeed = sv_maxspeed*maxspd_mod;
804 wishspeed = wishspeed * 0.5;
805 if (time >= self.teleport_time)
807 f = wishspeed - (self.velocity * wishdir);
809 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
814 // we get here if we ran out of ammo
815 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
816 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
820 maxairspd = sv_maxairspeed*maxspd_mod;
821 airaccel = sv_airaccelerate*maxspd_mod;
825 maxairspd = sv_maxairspeed;
826 airaccel = sv_airaccelerate;
829 makevectors(self.v_angle_y * '0 1 0');
830 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
832 wishdir = normalize(wishvel);
833 wishspeed = vlen(wishvel);
834 if (wishspeed > maxairspd)
835 wishspeed = maxairspd;
837 wishspeed = wishspeed * 0.5;
838 if (time >= self.teleport_time)
840 // NOTE: this does the same as the commented out old code if:
842 // sv_airaccel_sideways_friction 0
847 vel_straight = self.velocity * wishdir;
848 vel_z = self.velocity_z;
849 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
851 f = wishspeed - vel_straight;
853 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
855 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
857 // anti-sideways friction to fix QW-style bunnyhopping
858 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
860 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
863 f = wishspeed;// - (self.velocity * wishdir);
865 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
871 if(self.flags & FL_ONGROUND)
872 self.lastground = time;
874 self.lastflags = self.flags;
875 self.lastclassname = self.classname;