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;
353 void Nixnex_GiveCurrentWeapon();
354 void SV_PlayerPhysics()
356 local vector wishvel, wishdir, v;
357 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
360 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;
361 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
363 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
364 self.parm_idlesince = time;
366 self.buttons_old = buttons;
367 self.movement_old = self.movement;
368 self.v_angle_old = self.v_angle;
370 if(time > self.shtest_next)
372 if(self.shtest_next > 0)
374 // self.shtest_accumulator:
375 // started at time - SHTEST_DELTA
376 // should be at SHTEST_DELTA
377 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
378 if(shtest_score > SHTEST_THRESHOLD)
379 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
380 else if(cvar("developer_shtest"))
381 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
383 self.shtest_next = time + SHTEST_DELTA;
384 self.shtest_accumulator = 0;
386 self.shtest_accumulator += frametime;
388 if (clienttype(self) == CLIENTTYPE_BOT)
391 if (self.movetype == MOVETYPE_NONE && self.disableclientprediction != 2)
394 if (self.punchangle != '0 0 0')
396 f = vlen(self.punchangle) - 10 * frametime;
398 self.punchangle = normalize(self.punchangle) * f;
400 self.punchangle = '0 0 0';
403 if (self.punchvector != '0 0 0')
405 f = vlen(self.punchvector) - 30 * frametime;
407 self.punchvector = normalize(self.punchvector) * f;
409 self.punchvector = '0 0 0';
416 if(self.runes & RUNE_SPEED)
418 if(self.runes & CURSE_SLOW)
419 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
421 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
423 else if(self.runes & CURSE_SLOW)
425 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
429 if(g_minstagib && (self.items & IT_INVINCIBLE))
431 maxspd_mod = cvar("g_minstagib_speed_moverate");
436 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
439 if(self.flags & FL_NOTARGET)
441 maxspd_mod = cvar("sv_spectator_speed_multiplier");
442 if(!self.spectatorspeed)
443 self.spectatorspeed = maxspd_mod;
444 if(self.impulse && self.impulse <= 19)
446 if(self.lastflags & FL_NOTARGET)
448 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
449 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
450 else if(self.impulse == 11)
451 self.spectatorspeed = maxspd_mod;
452 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
453 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
454 else if(self.impulse >= 1 && self.impulse <= 9)
455 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
456 } // otherwise just clear
459 maxspd_mod = self.spectatorspeed;
462 spd = sv_maxspeed * maxspd_mod * swampspd_mod;
464 if(self.speed != spd)
468 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
469 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
470 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
471 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
473 temps = ftos(sv_accelerate * maxspd_mod);
474 stuffcmd(self, strcat("cl_movement_accelerate ", temps, "\n"));
477 // if dead, behave differently
481 if (!self.fixangle && !g_bugrigs)
484 self.angles_y = self.v_angle_y;
488 if(self.flags & FL_ONGROUND)
493 if(self.waterlevel < WATERLEVEL_SWIMMING)
494 if(time >= self.ladder_time)
497 self.nextstep = time + 0.3 + random() * 0.1;
498 trace_dphitq3surfaceflags = 0;
499 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
500 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
502 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
503 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
505 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
513 if(self.classname == "player")
517 self.flags &~= FL_ONGROUND;
518 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
519 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
520 self.flags |= FL_ONGROUND;
523 if (self.BUTTON_JUMP)
526 self.flags |= FL_JUMPRELEASED;
528 if (self.waterlevel == WATERLEVEL_SWIMMING)
531 if (g_jetpack && self.BUTTON_HOOK)
533 //makevectors(self.v_angle_y * '0 1 0');
534 makevectors(self.v_angle);
535 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
536 // add remaining speed as Z component
537 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
538 wishvel_x *= 1 / maxairspd;
539 wishvel_y *= 1 / maxairspd;
541 wishvel_z += sqrt(max(0, 1 - wishvel * wishvel));
542 wishvel_z += cvar("g_jetpack_accel_upadjust");
543 wishvel = normalize(wishvel);
544 wishvel_x *= cvar("g_jetpack_accel_side");
545 wishvel_y *= cvar("g_jetpack_accel_side");
546 wishvel_z *= cvar("g_jetpack_accel_up");
548 wishdir = normalize(wishvel);
549 wishspeed = vlen(wishvel);
551 f = (1 - (self.velocity * wishdir) / cvar("g_jetpack_maxspeed"));
552 if(cvar("g_jetpack_ammo"))
554 if(self.ammo_cells < 0.01)
557 f = min(f, self.ammo_cells / (cvar("g_jetpack_ammo") * frametime));
561 self.velocity = self.velocity + wishvel * f * frametime;
564 self.ammo_cells -= frametime * cvar("g_jetpack_ammo") * f;
565 if(floor(c / 5) != floor(self.ammo_cells / 5))
566 sprint(self, "jetpack: less than ", ftos(floor(c)), " cells left\n");
567 else if(self.ammo_cells < 0.01 && cvar("g_jetpack_ammo"))
568 sprint(self, "jetpack: out of ammo\n");
569 self.flags &~= FL_ONGROUND;
570 self.modelflags |= MF_ROCKET;
573 self.modelflags &~= MF_ROCKET;
576 self.modelflags &~= MF_ROCKET;
579 if (self.flags & FL_WATERJUMP )
581 self.velocity_x = self.movedir_x;
582 self.velocity_y = self.movedir_y;
583 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
585 self.flags &~= FL_WATERJUMP;
586 self.teleport_time = 0;
589 else if (g_bugrigs && self.classname == "player")
593 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
595 // noclipping or flying
596 self.flags &~= FL_ONGROUND;
598 self.velocity = self.velocity * (1 - frametime * sv_friction);
599 makevectors(self.v_angle);
600 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
601 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
603 wishdir = normalize(wishvel);
604 wishspeed = vlen(wishvel);
605 if (wishspeed > sv_maxspeed*maxspd_mod)
606 wishspeed = sv_maxspeed*maxspd_mod;
607 if (time >= self.teleport_time)
609 f = wishspeed - (self.velocity * wishdir);
611 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
614 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
617 self.flags &~= FL_ONGROUND;
619 makevectors(self.v_angle);
620 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
621 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
622 if (wishvel == '0 0 0')
623 wishvel = '0 0 -60'; // drift towards bottom
625 wishdir = normalize(wishvel);
626 wishspeed = vlen(wishvel);
627 if (wishspeed > sv_maxspeed*maxspd_mod)
628 wishspeed = sv_maxspeed*maxspd_mod;
629 wishspeed = wishspeed * 0.7;
632 self.velocity = self.velocity * (1 - frametime * sv_friction);
634 // water acceleration
635 f = wishspeed - (self.velocity * wishdir);
637 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
639 else if (time < self.ladder_time)
641 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
642 self.flags &~= FL_ONGROUND;
644 self.velocity = self.velocity * (1 - frametime * sv_friction);
645 makevectors(self.v_angle);
646 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
647 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
649 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
651 self.velocity_z = self.velocity_z + sv_gravity * frametime;
652 if (self.ladder_entity.classname == "func_water")
655 if (f > self.ladder_entity.speed)
656 wishvel = wishvel * (self.ladder_entity.speed / f);
658 self.watertype = self.ladder_entity.skin;
659 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
660 if ((self.origin_z + self.view_ofs_z) < f)
661 self.waterlevel = WATERLEVEL_SUBMERGED;
662 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
663 self.waterlevel = WATERLEVEL_SWIMMING;
664 else if ((self.origin_z + self.mins_z + 1) < f)
665 self.waterlevel = WATERLEVEL_WETFEET;
668 self.waterlevel = WATERLEVEL_NONE;
669 self.watertype = CONTENT_EMPTY;
673 wishdir = normalize(wishvel);
674 wishspeed = vlen(wishvel);
675 if (wishspeed > sv_maxspeed)
676 wishspeed = sv_maxspeed;
677 if (time >= self.teleport_time)
679 f = wishspeed - (self.velocity * wishdir);
681 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
684 else if (self.flags & FL_ONGROUND)
687 makevectors(self.v_angle_y * '0 1 0');
688 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
690 if(!(self.lastflags & FL_ONGROUND))
692 if(cvar("speedmeter"))
693 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
694 if(self.lastground < time - 0.3)
695 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
696 if(self.jumppadcount > 1)
697 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
698 self.jumppadcount = 0;
701 if (self.velocity_x || self.velocity_y)
702 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
707 if (f < sv_stopspeed)
708 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
710 f = 1 - frametime * sv_friction;
712 self.velocity = self.velocity * f;
714 self.velocity = '0 0 0';
717 wishdir = normalize(wishvel);
718 wishspeed = vlen(wishvel);
719 if (wishspeed > sv_maxspeed*maxspd_mod)
720 wishspeed = sv_maxspeed*maxspd_mod;
722 wishspeed = wishspeed * 0.5;
723 if (time >= self.teleport_time)
725 f = wishspeed - (self.velocity * wishdir);
727 self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed);
734 maxairspd = sv_maxairspeed*maxspd_mod;
735 airaccel = sv_airaccelerate*maxspd_mod;
739 maxairspd = sv_maxairspeed;
740 airaccel = sv_airaccelerate;
743 makevectors(self.v_angle_y * '0 1 0');
744 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
746 wishdir = normalize(wishvel);
747 wishspeed = vlen(wishvel);
748 if (wishspeed > maxairspd)
749 wishspeed = maxairspd;
751 wishspeed = wishspeed * 0.5;
752 if (time >= self.teleport_time)
754 // NOTE: this does the same as the commented out old code if:
756 // sv_airaccel_sideways_friction 0
761 vel_straight = self.velocity * wishdir;
762 vel_z = self.velocity_z;
763 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
765 f = wishspeed - vel_straight;
767 vel_straight = vel_straight + min(f, airaccel * frametime * wishspeed) * sv_airaccel_qw;
769 vel_straight = vel_straight + min(wishspeed, airaccel * frametime * wishspeed) * (1 - sv_airaccel_qw);
771 // anti-sideways friction to fix QW-style bunnyhopping
772 vel_perpend = vel_perpend * (1 - frametime * (wishspeed / maxairspd) * sv_airaccel_sideways_friction);
774 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
777 f = wishspeed;// - (self.velocity * wishdir);
779 self.velocity = self.velocity + wishdir * min(f, airaccel * frametime * wishspeed);
784 if(self.flags & FL_ONGROUND)
785 self.lastground = time;
787 self.lastflags = self.flags;