14 .string lastclassname;
16 .float() PlayerPhysplug;
17 float AdjustAirAccelQW(float accelqw, float factor);
24 .float stat_sv_airaccel_qw;
25 .float stat_sv_airstrafeaccel_qw;
26 .float stat_sv_airspeedlimit_nonqw;
27 .float stat_sv_maxspeed;
28 .float stat_movement_highspeed;
30 .float stat_jetpack_accel_side;
31 .float stat_jetpack_accel_up;
32 .float stat_jetpack_antigravity;
33 .float stat_jetpack_fuel;
34 .float stat_jetpack_maxspeed_up;
35 .float stat_jetpack_maxspeed_side;
37 void Physics_AddStats()
39 // g_movementspeed hack
40 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
41 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
42 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
43 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
44 addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
47 addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
48 addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
49 addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
50 addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
51 addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
52 addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
55 void Physics_UpdateStats(float maxspd_mod)
57 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
58 if (autocvar_sv_airstrafeaccel_qw)
59 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
61 self.stat_sv_airstrafeaccel_qw = 0;
62 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
63 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
64 self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
66 self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
67 self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
68 self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
69 self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
70 self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
71 self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
75 float IsMoveInDirection(vector mv, float angle) // key mix factor
77 if (mv_x == 0 && mv_y == 0)
78 return 0; // avoid division by zero
79 angle -= RAD2DEG * atan2(mv_y, mv_x);
80 angle = remainder(angle, 360) / 45;
81 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
84 float GeomLerp(float a, float lerp, float b)
86 return a == 0 ? (lerp < 1 ? 0 : b)
87 : b == 0 ? (lerp > 0 ? 0 : a)
88 : a * pow(fabs(b / a), lerp);
91 noref float pmove_waterjumptime;
93 const float unstick_count = 27;
94 vector unstick_offsets[unstick_count] =
96 // 1 no nudge (just return the original if this test passes)
99 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
100 '-0.125 0.000 0.000', '0.125 0.000 0.000',
101 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
102 // 4 diagonal flat nudges
103 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
104 '-0.125 0.125 0.000', '0.125 0.125 0.000',
105 // 8 diagonal upward nudges
106 '-0.125 0.000 0.125', '0.125 0.000 0.125',
107 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
108 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
109 '-0.125 0.125 0.125', '0.125 0.125 0.125',
110 // 8 diagonal downward nudges
111 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
112 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
113 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
114 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
117 void PM_ClientMovement_Unstick()
120 for (i = 0; i < unstick_count; i++)
122 vector neworigin = unstick_offsets[i] + self.origin;
123 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
124 if (!trace_startsolid)
126 self.origin = neworigin;
132 void PM_ClientMovement_UpdateStatus()
134 // make sure player is not stuck
135 PM_ClientMovement_Unstick();
138 if (PHYS_INPUT_BUTTON_CROUCH(self))
140 // wants to crouch, this always works..
141 if (!IS_DUCKED(self))
146 // wants to stand, if currently crouching we need to check for a
150 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
151 if (!trace_startsolid)
157 vector origin1 = self.origin + '0 0 1';
158 vector origin2 = self.origin - '0 0 1';
160 tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
161 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
165 // this code actually "predicts" an impact; so let's clip velocity first
166 float f = dotproduct(self.velocity, trace_plane_normal);
167 if (f < 0) // only if moving downwards actually
168 self.velocity -= f * trace_plane_normal;
171 UNSET_ONGROUND(self);
173 // set watertype/waterlevel
174 origin1 = self.origin;
175 origin1_z += self.mins_z + 1;
176 self.waterlevel = WATERLEVEL_NONE;
178 self.watertype = (pointcontents(origin1) == CONTENT_WATER);
182 self.waterlevel = WATERLEVEL_WETFEET;
183 origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
184 if(pointcontents(origin1) == CONTENT_WATER)
186 self.waterlevel = WATERLEVEL_SWIMMING;
187 origin1_z = self.origin_z + 22;
188 if(pointcontents(origin1) == CONTENT_WATER)
189 self.waterlevel = WATERLEVEL_SUBMERGED;
193 if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
194 pmove_waterjumptime = 0;
197 void PM_ClientMovement_Move()
200 float t = PHYS_INPUT_TIMELENGTH;
201 vector primalvelocity = self.velocity;
202 PM_ClientMovement_UpdateStatus();
204 for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
206 vector neworigin = self.origin + t * self.velocity;
207 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
208 float old_trace1_fraction = trace_fraction;
209 vector old_trace1_endpos = trace_endpos;
210 vector old_trace1_plane_normal = trace_plane_normal;
211 if (trace_fraction < 1 && trace_plane_normal_z == 0)
213 // may be a step or wall, try stepping up
214 // first move forward at a higher level
215 vector currentorigin2 = self.origin;
216 currentorigin2_z += PHYS_STEPHEIGHT;
217 vector neworigin2 = neworigin;
218 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
219 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
220 if (!trace_startsolid)
222 // then move down from there
223 currentorigin2 = trace_endpos;
224 neworigin2 = trace_endpos;
225 neworigin2_z = self.origin_z;
226 float old_trace2_fraction = trace_fraction;
227 vector old_trace2_plane_normal = trace_plane_normal;
228 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
229 //Con_Printf("%f %f %f %f : %f %f %f %f : %f %f %f %f\n", trace.fraction, trace.endpos[0], trace.endpos[1], trace.endpos[2], trace2.fraction, trace2.endpos[0], trace2.endpos[1], trace2.endpos[2], trace3.fraction, trace3.endpos[0], trace3.endpos[1], trace3.endpos[2]);
230 // accept the new trace if it made some progress
231 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
233 trace_fraction = old_trace2_fraction;
234 trace_endpos = trace_endpos;
235 trace_plane_normal = old_trace2_plane_normal;
239 trace_fraction = old_trace1_fraction;
240 trace_endpos = old_trace1_endpos;
241 trace_plane_normal = old_trace1_plane_normal;
246 // check if it moved at all
247 if (trace_fraction >= 0.001)
248 self.origin = trace_endpos;
250 // check if it moved all the way
251 if (trace_fraction == 1)
254 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
255 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
256 // this got commented out in a change that supposedly makes the code match QW better
257 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
258 if (trace_plane_normal_z > 0.7)
261 t -= t * trace_fraction;
263 float f = dotproduct(self.velocity, trace_plane_normal);
264 self.velocity -= f * trace_plane_normal;
266 if (pmove_waterjumptime > 0)
267 self.velocity = primalvelocity;
271 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
275 // this doesn't play well with analog input
276 if (PHYS_INPUT_MOVEVALUES(self).x == 0 || PHYS_INPUT_MOVEVALUES(self).y != 0)
277 return; // can't control movement if not moving forward or backward
280 k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
285 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
287 float zspeed = self.velocity_z;
289 float xyspeed = vlen(self.velocity);
290 self.velocity = normalize(self.velocity);
292 float dot = self.velocity * wishdir;
294 if (dot > 0) // we can't change direction while slowing down
296 k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
297 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
298 k *= PHYS_AIRCONTROL;
299 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
302 self.velocity = self.velocity * xyspeed;
303 self.velocity_z = zspeed;
306 float AdjustAirAccelQW(float accelqw, float factor)
308 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
311 // example config for alternate speed clamping:
312 // sv_airaccel_qw 0.8
313 // sv_airaccel_sideways_friction 0
314 // prvm_globalset server speedclamp_mode 1
316 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
318 float speedclamp = stretchfactor > 0 ? stretchfactor
319 : accelqw < 0 ? 1 // full clamping, no stretch
322 accelqw = fabs(accelqw);
324 if (GAMEPLAYFIX_Q2AIRACCELERATE)
325 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
327 float vel_straight = self.velocity * wishdir;
328 float vel_z = self.velocity_z;
329 vector vel_xy = vec2(self.velocity);
330 vector vel_perpend = vel_xy - vel_straight * wishdir;
332 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
334 float vel_xy_current = vlen(vel_xy);
336 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
337 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
338 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
339 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
340 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
342 if (sidefric < 0 && (vel_perpend*vel_perpend))
343 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
345 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
346 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
348 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
349 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
350 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
351 // obviously, this cannot be
357 vel_perpend *= max(fmin, f);
361 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
363 vel_xy = vel_straight * wishdir + vel_perpend;
367 float vel_xy_preclamp;
368 vel_xy_preclamp = vlen(vel_xy);
369 if (vel_xy_preclamp > 0) // prevent division by zero
371 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
372 if (vel_xy_current < vel_xy_preclamp)
373 vel_xy *= (vel_xy_current / vel_xy_preclamp);
377 self.velocity = vel_xy + vel_z * '0 0 1';
380 void PM_AirAccelerate(vector wishdir, float wishspeed)
385 vector curvel = self.velocity;
387 float curspeed = vlen(curvel);
389 if (wishspeed > curspeed * 1.01)
390 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
393 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
394 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
396 vector wishvel = wishdir * wishspeed;
397 vector acceldir = wishvel - curvel;
398 float addspeed = vlen(acceldir);
399 acceldir = normalize(acceldir);
401 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
403 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
405 vector curdir = normalize(curvel);
406 float dot = acceldir * curdir;
408 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
411 self.velocity += accelspeed * acceldir;
419 When you press the jump key
422 void PlayerJump (void)
425 if (PHYS_FROZEN(self))
426 return; // no jumping in freezetag when frozen
428 if (self.player_blocked)
429 return; // no jumping while blocked
431 float doublejump = FALSE;
432 float mjumpheight = PHYS_JUMPVELOCITY;
434 player_multijump = doublejump;
435 player_jumpheight = mjumpheight;
436 if (MUTATOR_CALLHOOK(PlayerJump))
439 doublejump = player_multijump;
440 mjumpheight = player_jumpheight;
442 if (autocvar_sv_doublejump)
444 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
445 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
449 // we MUST clip velocity here!
451 f = self.velocity * trace_plane_normal;
453 self.velocity -= f * trace_plane_normal;
457 if (self.waterlevel >= WATERLEVEL_SWIMMING)
459 self.velocity_z = PHYS_MAXSPEED(self) * 0.7;
464 if (!IS_ONGROUND(self))
467 if (self.cvar_cl_movement_track_canjump)
468 if (!(self.flags & FL_JUMPRELEASED))
471 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
472 // velocity bounds. Final velocity is bound between (jumpheight *
473 // min + jumpheight) and (jumpheight * max + jumpheight);
475 if (autocvar_sv_jumpspeedcap_min != "")
477 float minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
479 if (self.velocity_z < minjumpspeed)
480 mjumpheight += minjumpspeed - self.velocity_z;
483 if (autocvar_sv_jumpspeedcap_max != "")
485 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
486 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
488 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
490 float maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
492 if (self.velocity_z > maxjumpspeed)
493 mjumpheight -= self.velocity_z - maxjumpspeed;
497 if (!(self.lastflags & FL_ONGROUND))
499 if (autocvar_speedmeter)
500 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
501 if (self.lastground < time - 0.3)
503 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
504 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
506 if (self.jumppadcount > 1)
507 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
508 self.jumppadcount = 0;
511 self.oldvelocity_z = self.velocity_z += mjumpheight;
513 UNSET_ONGROUND(self);
514 self.flags &= ~FL_JUMPRELEASED;
516 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
518 if (autocvar_g_jump_grunt)
519 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
521 self.restart_jump = -1; // restart jump anim next time
522 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
526 void CheckWaterJump()
528 // check for a jump-out-of-water
529 makevectors(PHYS_INPUT_ANGLES(self));
530 vector start = self.origin;
533 normalize(v_forward);
534 vector end = start + v_forward*24;
535 traceline (start, end, TRUE, self);
536 if (trace_fraction < 1)
538 start_z = start_z + self.maxs_z - 8;
539 end = start + v_forward*24;
540 self.movedir = trace_plane_normal * -50;
541 traceline(start, end, TRUE, self);
542 if (trace_fraction == 1)
543 { // open at eye level
544 self.velocity_z = 225;
546 self.flags |= FL_WATERJUMP;
547 self.flags &= ~FL_JUMPRELEASED;
548 self.teleport_time = time + 2; // safety net
554 void CheckPlayerJump()
557 if (self.BUTTON_JUMP)
560 self.flags |= FL_JUMPRELEASED;
563 if (self.waterlevel == WATERLEVEL_SWIMMING)
567 float racecar_angle(float forward, float down)
575 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
577 float angle_mult = forward / (800 + forward);
580 return ret * angle_mult + 360 * (1 - angle_mult);
582 return ret * angle_mult;
585 void RaceCarPhysics()
588 // using this move type for "big rigs"
589 // the engine does not push the entity!
593 vector angles_save = self.angles;
594 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / PHYS_MAXSPEED(self), 1);
595 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / PHYS_MAXSPEED(self), 1);
597 if (g_bugrigs_reverse_speeding)
601 // back accel is DIGITAL
602 // to prevent speedhack
612 makevectors(self.angles); // new forward direction!
614 if (IS_ONGROUND(self) || g_bugrigs_air_steering)
616 float myspeed = self.velocity * v_forward;
617 float upspeed = self.velocity * v_up;
619 // responsiveness factor for steering and acceleration
620 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
621 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
624 if (myspeed < 0 && g_bugrigs_reverse_spinning)
625 steerfactor = -myspeed * g_bugrigs_steer;
627 steerfactor = -myspeed * f * g_bugrigs_steer;
630 if (myspeed < 0 && g_bugrigs_reverse_speeding)
631 accelfactor = g_bugrigs_accel;
633 accelfactor = f * g_bugrigs_accel;
634 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
640 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
644 if (!g_bugrigs_reverse_speeding)
645 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
652 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
656 if (g_bugrigs_reverse_stopping)
659 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
662 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
663 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
665 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
666 makevectors(self.angles); // new forward direction!
668 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
670 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
674 float myspeed = vlen(self.velocity);
676 // responsiveness factor for steering and acceleration
677 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
678 float steerfactor = -myspeed * f;
679 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
681 rigvel = self.velocity;
682 makevectors(self.angles); // new forward direction!
685 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
686 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
687 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
688 //MAXIMA: solve(total_acceleration(v) = 0, v);
690 if (g_bugrigs_planar_movement)
692 vector rigvel_xy, neworigin, up;
695 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
696 rigvel_xy = vec2(rigvel);
698 if (g_bugrigs_planar_movement_car_jumping)
701 mt = MOVE_NOMONSTERS;
703 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
704 up = trace_endpos - self.origin;
706 // BUG RIGS: align the move to the surface instead of doing collision testing
708 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
711 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
713 if (trace_fraction < 0.5)
716 neworigin = self.origin;
719 neworigin = trace_endpos;
721 if (trace_fraction < 1)
723 // now set angles_x so that the car points parallel to the surface
724 self.angles = vectoangles(
725 '1 0 0' * v_forward_x * trace_plane_normal_z
727 '0 1 0' * v_forward_y * trace_plane_normal_z
729 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
735 // now set angles_x so that the car points forward, but is tilted in velocity direction
736 UNSET_ONGROUND(self);
739 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
740 self.movetype = MOVETYPE_NOCLIP;
744 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
745 self.velocity = rigvel;
746 self.movetype = MOVETYPE_FLY;
750 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
751 if (trace_fraction != 1)
753 self.angles = vectoangles2(
754 '1 0 0' * v_forward_x * trace_plane_normal_z
756 '0 1 0' * v_forward_y * trace_plane_normal_z
758 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
766 vel_local_x = v_forward * self.velocity;
767 vel_local_y = v_right * self.velocity;
768 vel_local_z = v_up * self.velocity;
770 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
771 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
775 vector vf1, vu1, smoothangles;
776 makevectors(self.angles);
777 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
782 makevectors(angles_save);
783 vf1 = vf1 + v_forward * (1 - f);
784 vu1 = vu1 + v_up * (1 - f);
785 smoothangles = vectoangles2(vf1, vu1);
786 self.angles_x = -smoothangles_x;
787 self.angles_z = smoothangles_z;
791 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
792 .float specialcommand_pos;
793 void SpecialCommand()
799 if (!CheatImpulse(99))
800 print("A hollow voice says \"Plugh\".\n");
806 float speedaward_speed;
807 string speedaward_holder;
808 string speedaward_uid;
810 void race_send_speedaward(float msg)
813 // send the best speed of the round
814 WriteByte(msg, SVC_TEMPENTITY);
815 WriteByte(msg, TE_CSQC_RACE);
816 WriteByte(msg, RACE_NET_SPEED_AWARD);
817 WriteInt24_t(msg, floor(speedaward_speed+0.5));
818 WriteString(msg, speedaward_holder);
823 float speedaward_alltimebest;
824 string speedaward_alltimebest_holder;
825 string speedaward_alltimebest_uid;
827 void race_send_speedaward_alltimebest(float msg)
830 // send the best speed
831 WriteByte(msg, SVC_TEMPENTITY);
832 WriteByte(msg, TE_CSQC_RACE);
833 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
834 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
835 WriteString(msg, speedaward_alltimebest_holder);
839 float PM_check_keepaway(void)
842 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
848 void PM_check_race_movetime(void)
851 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
852 float f = floor(self.race_movetime_frac);
853 self.race_movetime_frac -= f;
854 self.race_movetime_count += f;
855 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
859 float PM_check_specialcommand(float buttons)
865 else if (buttons == 1)
867 else if (buttons == 2)
869 else if (buttons == 128)
871 else if (buttons == 256)
873 else if (buttons == 512)
875 else if (buttons == 1024)
880 if (c == substring(specialcommand, self.specialcommand_pos, 1))
882 self.specialcommand_pos += 1;
883 if (self.specialcommand_pos >= strlen(specialcommand))
885 self.specialcommand_pos = 0;
890 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
891 self.specialcommand_pos = 0;
896 void PM_check_nickspam(void)
899 if (time >= self.nickspamtime)
901 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
903 // slight annoyance for nick change scripts
904 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
905 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
907 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
909 PHYS_INPUT_ANGLES(self)_x = random() * 360;
910 PHYS_INPUT_ANGLES(self)_y = random() * 360;
911 // at least I'm not forcing retardedview by also assigning to angles_z
912 self.fixangle = TRUE;
918 void PM_check_punch()
921 if (self.punchangle != '0 0 0')
923 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
925 self.punchangle = normalize(self.punchangle) * f;
927 self.punchangle = '0 0 0';
930 if (self.punchvector != '0 0 0')
932 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
934 self.punchvector = normalize(self.punchvector) * f;
936 self.punchvector = '0 0 0';
941 void PM_check_spider(void)
944 if (time >= self.spider_slowness)
946 PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
947 self.stat_sv_airspeedlimit_nonqw *= 0.5;
951 // predict frozen movement, as frozen players CAN move in some cases
952 void PM_check_frozen(void)
954 if (!PHYS_FROZEN(self))
956 if (PHYS_DODGING_FROZEN
958 && IS_REAL_CLIENT(self)
962 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
963 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
964 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
967 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
969 vector midpoint = ((self.absmin + self.absmax) * 0.5);
970 if (pointcontents(midpoint) == CONTENT_WATER)
972 self.velocity = self.velocity * 0.5;
974 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
975 self.velocity_z = 200;
979 void PM_check_blocked(void)
982 if (!self.player_blocked)
984 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
985 self.disableclientprediction = 1;
990 float speedaward_lastsent;
991 float speedaward_lastupdate;
992 string GetMapname(void);
994 void PM_check_race(void)
997 if not(g_cts || g_race)
999 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1001 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1002 speedaward_holder = self.netname;
1003 speedaward_uid = self.crypto_idfp;
1004 speedaward_lastupdate = time;
1006 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1008 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1009 race_send_speedaward(MSG_ALL);
1010 speedaward_lastsent = speedaward_speed;
1011 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1013 speedaward_alltimebest = speedaward_speed;
1014 speedaward_alltimebest_holder = speedaward_holder;
1015 speedaward_alltimebest_uid = speedaward_uid;
1016 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1017 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1018 race_send_speedaward_alltimebest(MSG_ALL);
1024 void PM_check_vortex(void)
1027 float xyspeed = vlen(vec2(self.velocity));
1028 if (self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1030 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1031 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1032 float f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1033 // add the extra charge
1034 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * PHYS_INPUT_TIMELENGTH);
1039 void PM_fly(float maxspd_mod)
1041 // noclipping or flying
1042 UNSET_ONGROUND(self);
1044 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1045 makevectors(PHYS_INPUT_ANGLES(self));
1046 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1047 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1048 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1049 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1051 vector wishdir = normalize(wishvel);
1052 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1053 if (time >= self.teleport_time)
1054 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1057 void PM_swim(float maxspd_mod)
1060 UNSET_ONGROUND(self);
1062 float jump = PHYS_INPUT_BUTTON_JUMP(self);
1063 // water jump only in certain situations
1064 // this mimics quakeworld code
1065 if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
1067 vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1068 makevectors(yawangles);
1069 vector forward = v_forward;
1070 vector spot = self.origin + 24 * forward;
1072 traceline(spot, spot, MOVE_NOMONSTERS, self);
1073 if (trace_startsolid)
1076 traceline(spot, spot, MOVE_NOMONSTERS, self);
1077 if (!trace_startsolid)
1079 self.velocity = forward * 50;
1080 self.velocity_z = 310;
1081 pmove_waterjumptime = 2;
1082 UNSET_ONGROUND(self);
1083 SET_JUMP_HELD(self);
1087 makevectors(PHYS_INPUT_ANGLES(self));
1088 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1089 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1090 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1091 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1092 if (wishvel == '0 0 0')
1093 wishvel = '0 0 -60'; // drift towards bottom
1095 vector wishdir = normalize(wishvel);
1096 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
1098 if (IS_DUCKED(self))
1101 // if (pmove_waterjumptime <= 0) // TODO: use
1104 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
1105 f = min(max(0, f), 1);
1108 f = wishspeed - self.velocity * wishdir;
1111 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
1112 self.velocity += accelspeed * wishdir;
1115 // holding jump button swims upward slowly
1119 if (self.watertype & CONTENT_LAVA)
1120 self.velocity_z = 50;
1121 else if (self.watertype & CONTENT_SLIME)
1122 self.velocity_z = 80;
1125 if (IS_NEXUIZ_DERIVED(gamemode))
1127 self.velocity_z = 200;
1130 self.velocity_z = 100;
1135 PM_ClientMovement_Move();
1136 // water acceleration
1137 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1140 void PM_ladder(float maxspd_mod)
1142 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1143 UNSET_ONGROUND(self);
1146 g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
1147 if (PHYS_ENTGRAVITY(self))
1148 g *= PHYS_ENTGRAVITY(self);
1149 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1152 self.velocity_z += g;
1155 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1156 makevectors(PHYS_INPUT_ANGLES(self));
1157 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1158 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1159 + v_right * PHYS_INPUT_MOVEVALUES(self)_y
1160 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self)_z;
1161 self.velocity_z += g;
1162 if (self.ladder_entity.classname == "func_water")
1164 float f = vlen(wishvel);
1165 if (f > self.ladder_entity.speed)
1166 wishvel *= (self.ladder_entity.speed / f);
1168 self.watertype = self.ladder_entity.skin;
1169 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1170 if ((self.origin_z + self.view_ofs_z) < f)
1171 self.waterlevel = WATERLEVEL_SUBMERGED;
1172 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1173 self.waterlevel = WATERLEVEL_SWIMMING;
1174 else if ((self.origin_z + self.mins_z + 1) < f)
1175 self.waterlevel = WATERLEVEL_WETFEET;
1178 self.waterlevel = WATERLEVEL_NONE;
1179 self.watertype = CONTENT_EMPTY;
1183 vector wishdir = normalize(wishvel);
1184 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1185 PM_ClientMovement_Move();
1187 if (time >= self.teleport_time)
1189 // water acceleration
1190 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1193 void PM_jetpack(float maxspd_mod)
1195 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1196 makevectors(PHYS_INPUT_ANGLES(self));
1197 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1198 + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
1199 // add remaining speed as Z component
1200 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1201 // fix speedhacks :P
1202 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1203 // add the unused velocity as up component
1206 // if (self.BUTTON_JUMP)
1207 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1209 // it is now normalized, so...
1210 float a_side = PHYS_JETPACK_ACCEL_SIDE;
1211 float a_up = PHYS_JETPACK_ACCEL_UP;
1212 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
1214 wishvel_x *= a_side;
1215 wishvel_y *= a_side;
1220 //////////////////////////////////////////////////////////////////////////////////////
1221 // finding the maximum over all vectors of above form
1222 // with wishvel having an absolute value of 1
1223 //////////////////////////////////////////////////////////////////////////////////////
1224 // we're finding the maximum over
1225 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1226 // for z in the range from -1 to 1
1227 //////////////////////////////////////////////////////////////////////////////////////
1228 // maximum is EITHER attained at the single extreme point:
1229 float a_diff = a_side * a_side - a_up * a_up;
1233 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1234 if (f > -1 && f < 1) // can it be attained?
1236 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1237 //print("middle\n");
1240 // OR attained at z = 1:
1241 f = (a_up + a_add) * (a_up + a_add);
1247 // OR attained at z = -1:
1248 f = (a_up - a_add) * (a_up - a_add);
1252 //print("bottom\n");
1255 //////////////////////////////////////////////////////////////////////////////////////
1257 //print("best possible acceleration: ", ftos(best), "\n");
1260 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1261 if (wishvel_z - PHYS_GRAVITY > 0)
1262 fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1264 fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1267 fvel = vlen(wishvel);
1270 wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
1272 fvel = min(1, vlen(wishvel) / best);
1273 if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1274 f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1278 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1280 if (f > 0 && wishvel != '0 0 0')
1282 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1283 UNSET_ONGROUND(self);
1286 if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1287 self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1289 self.items |= IT_USING_JETPACK;
1291 // jetpack also inhibits health regeneration, but only for 1 second
1292 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1297 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1298 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1299 self.velocity_z -= g * 0.5;
1301 self.velocity_z -= g;
1302 PM_ClientMovement_Move();
1303 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1304 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1305 self.velocity_z -= g * 0.5;
1309 void PM_walk(float buttons_prev, float maxspd_mod)
1312 // we get here if we ran out of ammo
1313 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1314 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1315 if (!(self.lastflags & FL_ONGROUND))
1317 if (autocvar_speedmeter)
1318 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1319 if (self.lastground < time - 0.3)
1320 self.velocity *= (1 - autocvar_sv_friction_on_land);
1321 if (self.jumppadcount > 1)
1322 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1323 self.jumppadcount = 0;
1327 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1328 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1329 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1331 vector wishdir = normalize(wishvel);
1332 float wishspeed = vlen(wishvel);
1334 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1335 if (IS_DUCKED(self))
1338 // apply edge friction
1339 float f = vlen(vec2(self.velocity));
1342 // TODO: apply edge friction
1343 // apply ground friction
1344 f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1348 Mathematical analysis time!
1350 Our goal is to invert this mess.
1352 For the two cases we get:
1353 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1354 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1355 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1357 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1358 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1360 These cases would be chosen ONLY if:
1362 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1363 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1365 v0 >= PHYS_STOPSPEED
1366 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1367 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1370 float addspeed = wishspeed - self.velocity * wishdir;
1373 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1374 self.velocity += accelspeed * wishdir;
1376 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1377 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1378 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1379 if (self.velocity * self.velocity)
1380 PM_ClientMovement_Move();
1381 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1382 if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1383 self.velocity_z -= g * 0.5;
1386 void PM_air(float buttons_prev, float maxspd_mod)
1389 // we get here if we ran out of ammo
1390 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && PHYS_AMMO_FUEL(self) < 0.01)
1391 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1393 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1394 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1395 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1397 vector wishdir = normalize(wishvel);
1398 float wishspeed = vlen(wishvel);
1401 if (time >= self.teleport_time)
1403 if (pmove_waterjumptime <= 0)
1406 float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1408 // apply air speed limit
1409 float airaccelqw = PHYS_AIRACCEL_QW(self);
1410 float wishspeed0 = wishspeed;
1411 wishspeed = min(wishspeed, maxairspd);
1412 if (IS_DUCKED(self))
1414 float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1416 float accelerating = (self.velocity * wishdir > 0);
1417 float wishspeed2 = wishspeed;
1420 if (PHYS_AIRSTOPACCELERATE)
1422 vector curdir = normalize(vec2(self.velocity));
1423 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1425 // note that for straight forward jumping:
1426 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1427 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1429 // dv/dt = accel * maxspeed (when slow)
1430 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1431 // log dv/dt = logaccel + logmaxspeed (when slow)
1432 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1433 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1434 if (PHYS_MAXAIRSTRAFESPEED)
1435 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1436 if (PHYS_AIRSTRAFEACCELERATE)
1437 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1438 if (PHYS_AIRSTRAFEACCEL_QW(self))
1440 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
1442 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
1445 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1446 PM_AirAccelerate(wishdir, wishspeed2);
1448 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1450 if (PHYS_AIRCONTROL)
1451 CPM_PM_Aircontrol(wishdir, wishspeed2);
1453 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1454 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1455 self.velocity_z -= g * 0.5;
1457 self.velocity_z -= g;
1458 PM_ClientMovement_Move();
1459 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1460 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1461 self.velocity_z -= g * 0.5;
1464 // used for calculating airshots
1465 float PM_is_flying()
1467 if (IS_ONGROUND(self))
1469 if (self.waterlevel >= WATERLEVEL_SWIMMING)
1471 traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
1472 return trace_fraction >= 1;
1477 float buttons = PHYS_INPUT_BUTTON_MASK(self);
1479 //Con_Printf(" %f", PHYS_INPUT_TIMELENGTH);
1480 if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
1481 UNSET_JUMP_HELD(self); // canjump = true
1482 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1483 PM_ClientMovement_UpdateStatus();
1487 WarpZone_PlayerPhysics_FixVAngle();
1489 float maxspeed_mod = 1;
1490 maxspeed_mod *= PM_check_keepaway();
1491 maxspeed_mod *= PHYS_HIGHSPEED;
1494 Physics_UpdateStats(maxspeed_mod);
1496 if (self.PlayerPhysplug)
1497 if (self.PlayerPhysplug())
1501 PM_check_race_movetime();
1503 anticheat_physics();
1506 if (PM_check_specialcommand(buttons))
1511 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1512 self.parm_idlesince = time;
1515 float buttons_prev = self.buttons_old;
1516 self.buttons_old = buttons;
1517 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1518 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1520 PM_check_nickspam();
1524 if (IS_BOT_CLIENT(self))
1526 if (playerdemo_read())
1531 self.items &= ~IT_USING_JETPACK;
1533 if (IS_PLAYER(self))
1537 if (self.race_penalty)
1538 if (time > self.race_penalty)
1539 self.race_penalty = 0;
1542 float not_allowed_to_move = 0;
1544 if (self.race_penalty)
1545 not_allowed_to_move = 1;
1548 if (!autocvar_sv_ready_restart_after_countdown)
1549 if (time < game_starttime)
1550 not_allowed_to_move = 1;
1553 if (not_allowed_to_move)
1555 self.velocity = '0 0 0';
1556 self.movetype = MOVETYPE_NONE;
1558 self.disableclientprediction = 2;
1562 else if (self.disableclientprediction == 2)
1564 if (self.movetype == MOVETYPE_NONE)
1565 self.movetype = MOVETYPE_WALK;
1566 self.disableclientprediction = 0;
1572 if (self.movetype == MOVETYPE_NONE)
1575 // when we get here, disableclientprediction cannot be 2
1576 self.disableclientprediction = 0;
1588 if (self.in_swamp) {
1589 maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1594 // conveyors: first fix velocity
1595 if (self.conveyor.state)
1596 self.velocity -= self.conveyor.movedir;
1600 MUTATOR_CALLHOOK(PlayerPhysics);
1602 // float forcedodge = 1;
1605 // PM_dodging_checkpressedkeys();
1608 // PM_ClientMovement_Move();
1613 if (!IS_PLAYER(self))
1615 maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
1616 if (!self.spectatorspeed)
1617 self.spectatorspeed = maxspeed_mod;
1618 if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
1620 if (self.lastclassname != "player")
1622 if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
1623 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
1624 else if (self.impulse == 11)
1625 self.spectatorspeed = maxspeed_mod;
1626 else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
1627 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
1628 else if (self.impulse >= 1 && self.impulse <= 9)
1629 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
1630 } // otherwise just clear
1633 maxspeed_mod *= self.spectatorspeed;
1638 // if dead, behave differently
1639 // in CSQC, physics don't handle dead player
1645 if (!self.fixangle && !g_bugrigs)
1646 self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1650 if (IS_ONGROUND(self))
1651 if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
1655 if (self.waterlevel < WATERLEVEL_SWIMMING)
1656 if (time >= self.ladder_time)
1659 self.nextstep = time + 0.3 + random() * 0.1;
1660 trace_dphitq3surfaceflags = 0;
1661 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1662 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
1664 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
1665 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1667 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1677 if (IS_PLAYER(self))
1682 if (self.flags & /* FL_WATERJUMP */ 2048)
1684 self.velocity_x = self.movedir_x;
1685 self.velocity_y = self.movedir_y;
1686 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
1688 self.flags &= ~/* FL_WATERJUMP */ 2048;
1689 self.teleport_time = 0;
1694 else if (g_bugrigs && IS_PLAYER(self))
1698 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
1699 PM_fly(maxspeed_mod);
1701 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1702 PM_swim(maxspeed_mod);
1704 else if (time < self.ladder_time)
1705 PM_ladder(maxspeed_mod);
1707 else if ((ITEMS(self) & IT_JETPACK) && PHYS_INPUT_BUTTON_HOOK(self) && (!PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) > 0 || (ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO)) && !PHYS_FROZEN(self))
1708 PM_jetpack(maxspeed_mod);
1713 // jump if on ground with jump button pressed but only if it has been
1714 // released at least once since the last jump
1715 if (PHYS_INPUT_BUTTON_JUMP(self))
1717 if (IS_ONGROUND(self) && (!IS_JUMP_HELD(self) || !cvar("cl_movement_track_canjump")))
1719 self.velocity_z += PHYS_JUMPVELOCITY;
1720 UNSET_ONGROUND(self);
1721 SET_JUMP_HELD(self); // canjump = false
1725 UNSET_JUMP_HELD(self); // canjump = true
1727 if (IS_ONGROUND(self))
1728 PM_walk(buttons_prev, maxspeed_mod);
1730 PM_air(buttons_prev, maxspeed_mod);
1734 if (!IS_OBSERVER(self))
1740 if (IS_ONGROUND(self))
1741 self.lastground = time;
1744 // conveyors: then break velocity again
1745 if (self.conveyor.state)
1746 self.velocity += self.conveyor.movedir;
1748 self.lastflags = self.flags;
1749 self.lastclassname = self.classname;
1752 void CSQC_ClientMovement_PlayerMove_Frame()
1754 // if a move is more than 50ms, do it as two moves (matching qwsv)
1755 //Con_Printf("%i ", self.cmd.msec);
1756 if (PHYS_INPUT_TIMELENGTH > 0.0005)
1758 if (PHYS_INPUT_TIMELENGTH > 0.05)
1760 PHYS_INPUT_TIMELENGTH /= 2;
1766 // we REALLY need this handling to happen, even if the move is not executed
1767 if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
1768 UNSET_JUMP_HELD(self); // canjump = true
1773 void SV_PlayerPhysics(void)