3. Player fundamentals¶
The player refers to the self. Specifically it is not necessarily you, but rather the self in the Half-Life universe.
3.1. Input¶
All player movements can be controlled through commands. In the default game setup, pressing down the “W” key usually results in the +forward command being issued. Releasing the same key will cause -forward to be issued. This is because the “W” key is bound to the +forward command with the bind command, usually issued from config.cfg. The -forward command need not be explicitly bound.
There are many similar commands available. It is beyond the scope of this documentation to provide a detailed description for all commands and indeed all cvars. The reader is invited to generate a list of all commands with the cmdlist command and study the SDK code for each of them.
There are, however, a few points to note about command issuing that are of concern to speedrunning. One of them is the impulse down phenomena. This affects primarily the viewangles (see Viewangles) and the FSU (see Forwardmove, sidemove, and upmove) computations. For example, the viewangles are typically changed by one of the viewangles commands such as +left for yawing left. This is done by adding to subtracting the viewangles by the value
The “key state” is the state of the command being issued (+left for example). The key state is typically 1, but in the first frame in which the command is being issued the value is 0.5. In other words, the change in viewangles is half of what it normally is in the first frame of the active command.
This is not limited to the viewangles. The FSU values (which is crucial to player movement as will be described in Forwardmove, sidemove, and upmove) are also affected by the impulse down. For example, by issuing +forward, the following value will be added to
Again, the key state here is typically 1, except the first frame of the +forward command. This can result in a noticeably drop in player acceleration.
Tip
The reader is advised to perform a detailed study of cl_dlls/input.cpp to understand the processes and computations involved to greater depths.
3.2. Viewangles¶
The term viewangles is usually associated with the player entity. The viewangles refer to a group of three angles which describe the player’s view orientation. We call these angles yaw, pitch and roll. Mathematically, we denote the yaw by
and the pitch by
Note that these are different from
Fig. 3.1. Illustration of the geometric meaning of
One way to change the yaw and pitch is by moving the mouse. This is not useful for tool-assisted speedrunning, however. A better method for precise control of the yaw and pitch angles is by issuing the commands +left, +right, +up, or +down. When these commands are active, the game increments or decrements the yaw or pitch by a certain controllable amount per frame. The amounts can be controlled by adjusting the variables cl_yawspeed and cl_pitchspeed. For instance, when +right is active, the game multiplies the value of cl_yawspeed by the frame time, then subtracts the result from the yaw angle.
3.2.1. Anglemod¶
When the viewangles are sent to the server, their values in degrees are rounded slightly using the anglemod function, which will be denoted
Definition 3.1 (Integer truncation)
For all
where
Definition 3.2 (Degrees-anglemod)
The degrees-anglemod function
where AND is the bitwise AND binary operator.
Definition 3.3 (Radians-anglemod)
The radians-anglemod function
To illustrate, we have the following examples of the output of degrees-anglemod.
The philosophy behind the anglemod function is to “wrap” the input angle into the range of fmod standard library function in C. Incidentally, the CryEngine 1 also contains small uses of anglemod, though it’s not used for view computation.
Definition 3.4 (Real version of modulo)
A version of the modulo binary operator
Anglemod, then, is an approximation of
Lemma 3.1 is useful for converting the bitwise AND operation into the mathematically more well understood and convenient
Lemma 3.1 (Equivalence of bitwise AND and modulo)
Let
Proof. Assume
Now assume
Namely, the most significant sign bit will be cleared as a result of masking out the least significant
as required.
Lemma 3.2 (Partial periodicity of anglemod)
The degrees-anglemod
Proof. Assume
Now assume
Theorem 3.1 (Error bounds of anglemod)
Let
Proof. Let
Suppose
where we have set
Suppose
Finally, suppose
Note that the assumption
This gives us the bounds
As stated by Theorem 3.1, anglemod introduces a loss of precision in setting angles. This can result in a loss of optimality in strafing. There are two ways to reduce the effects of anglemod, namely by the simple anglemod compensation and the more advanced vectorial compensation. These techniques will be described in Vectorial compensation.
3.3. View vectors¶
There are two vectors associated with the player’s viewangles. These are called the view vectors. For discussions in 3D space, they are defined to be
We will refer to the former as the unit forward vector and the latter as the unit right vector. The negative sign for
We sometimes restrict our discussions to the horizontal plane, such as in the description of strafing. In this case we assume
Such restriction is equivalent to projecting the
The above definitions are not valid if the roll is nonzero. Nevertheless, the roll is very rarely nonzero in practice, and so it rarely affects the physics described in this document, if at all.
3.4. Punchangles¶
The punchangles can refer to the client side or the server side values. The client side punchangles are usually affected by weapon recoil and are cosmetic in nature. Namely, they do not affect the aiming viewangles of the player. The player may be aiming with zero pitch while the camera appears to point elsewhere. The server side punchangles, on the other hand, affects the viewangles and therefore the aiming. The server side punchangles are affected by certain types of damage (see Health and damage) and punches from monsters (which are different from the purely damage itself).
The punchangles may be denoted as
The punchangles are rarely big issues except when the punch yaw and punch roll are nonzero. In these cases, strafing (Strafing) can be affected. Though this very rarely happens.
When a saveload is performed, the punchangles will be added to the viewangles permanently, while the punchangles will be set to zero. When this happens, the viewangles will not be reduced gradually like the case when punchangles are nonzero.
3.5. Forwardmove, sidemove, and upmove¶
When the movement keys are held, there exists three values,
+forwardand+backAssigns the positive or negative
cl_forwardspeedto˜ 𝐹 +moverightand+moveleftAssigns the positive or negative
cl_sidespeedto˜ 𝑆 +moveupand+movedownAssigns the positive or negative
cl_upspeedto˜ 𝑈
This is done at client side. Before sending these values to the server, however, they will be truncated to integers and clamped to sv_maxspeed. Then, PM_CheckParamters [sic] computes the final server side FSU values such that, assuming not all of FSU are zero,
If all of FSU are zero, then nothing is done and they remain zero.