6. Strafing¶
Strafing in the context of Half-Life speedrunning refers to the technique of pressing the correct movement keys (usually the WASD keys) and moving the mouse left and right in a precise way to increase the player speed beyond what the developers intended or make sharp turns without sacrificing too much speed. Strafing as a technique can be achieved similarly in the air and on the ground. If there is a need to distinguish between them, we refer to the former as “airstrafing” and the latter as “groundstrafing”. Strafing is commonly accompanied by a series of jumps intended to keep the player off the ground, as there is friction when moving on the ground. For the purpose of our discussions, the sole act of jumping repeatedly like a rabbit, regardless of whether strafing is done concurrently, is bunnyhopping, although the reader will find some in the community who include airstrafing when the term “bunnyhopping” is used. In this chapter, we will only discuss strafing and not bunnyhopping.
While this chapter is not the first mathematical treatment of this topic, it is the goal of the author to write the definitive analysis and optimisation of strafing in a significantly greater level of precision and thoroughness than seen in other sources. This chapter shall serve as the starting point and baseline for further discussions and analysis of strafing-related techniques and physics. Other attempts at mathematical treatments of strafing like this by injx, this by flafla2, this by Kared13, this by ZdrytchX, this by jrsala, and this by Matt’s Ramblings, are ad-hoc and suffer from flaws that make them less suited for further analyses (e.g. surfing analysis, speed-preserving strafing, curvature analysis, minimal-time paths), gaining a deeper understanding of strafing, or indeed for practical implementations.
Strafing is so fundamental to speedrunning, that a speedrunner ought to “get it out of the way” while focusing on other techniques. Strafing should be viewed as a building block that is used as a basis for other speedrunning techniques and tricks. If we do not cannot perform strafing near optimally, the entire speedrun falls apart. This applies to TASes as well: we want to optimise strafing as much as possible so that we can “forget about it” when constructing a TAS and permitting us to concentrate on the planning, the “general picture”, and executing specific tricks.
Tip
Be sure to familiarise yourself with the fundamentals of player movement described in Player movement basics. Without the prerequisite knowledge, this chapter can be hard to follow.
6.1. Basic intuition¶
Before delving into the mathematics, it may be helpful to have a geometric intuition of how strafing works. In Half-Life, and indeed in real-life classical mechanics, the velocity and acceleration are defined as Euclidean vectors with a length (or magnitude) and a direction, typically drawn as an arrow in the Euclidean space. In the strafing context, we are only interested in vectors drawn on a 2D space. When a body in Half-Life accelerates in a frame, the acceleration vector, scaled by frame time, is added to the velocity vector to obtain a new velocity vector,
This may be interpreted geometrically as putting the acceleration arrow after the velocity arrow to obtain a new velocity arrow. The diagram looks like a triangle, as seen in Fig. 6.1.. Now, notice that the new velocity arrow is longer than the previous velocity arrow. This means that the speed (represented by the arrow length) has been increased.
Fig. 6.1. Depiction of how strafing increases speed (i.e. the length of the velocity vector). On the left, the directions of the vectors have significance. On the right, we have rotated the vectors to that they line up, but therefore do not point to the correct direction (though having the correct length or magnitude).¶
In Half-Life physics, the magnitude or length of the acceleration vector
6.2. Building blocks¶
Regardless of the objective of strafing, its physics is governed by the fundamental movement equation (FME). We will construct several few mathematical building blocks to aid further analyses. Firstly, write
This can be done because the dot product satisfies the distributive law. Very quickly, we obtained (6.1) which is sometimes called the scalar FME, often used in practical applications as the most general way to compute new speeds (as opposed to velocity vectors) given
Tip
This is a very common and useful trick that can be used to quickly yield an expression for the magnitude of vectorial outputs without explicit vectorial computations or geometric analyses. Half-Life physicists ought to learn this technique well.
From equation (6.1), we can further write down the equations by assuming
Note that when
Assuming
Note
Note that we permit
Putting these together, we can write the
The new speed
However, computing speeds is sometimes not sufficient. We sometimes want to also compute velocity vectors endowed with both directionality and magnitude, but without worrying about player viewangles and
This is a matrix multiplication of
Caution
Remember from Notations Used that vectors in this documentation are row vectors. Therefore, the order of multiplication is different from those in standard linear algebra textbooks. In fact, the components in
With this idea in mind, we can rewrite the FME as
Note that the precaution
When written in the form of (6.4), positive
6.3. Maximum acceleration¶
Airstrafing to continuously gain speed beyond what the developers intended is one of the oldest speedrunning tricks. It is of no surprise that one of the earliest inquiries into Half-Life physics is related to the question of how to airstrafe with the maximum acceleration, when research began circa 2012 by the author of this documentation. In this section, we will provide precise mathematical descriptions of how maximum-acceleration strafing works in a way that will provide a baseline for further analyses and also can readily be implemented in TAS tools.
We must define our metric for “maximum acceleration” in a mathematically precise way. Specifically, we want to maximise the average scalar acceleration over some period of time
where
6.3.1. Arguments of the maxima¶
Let
It turns out that maximising the per-frame acceleration “greedily” also maximises the global average acceleration over the span of some time
Now, we will assume
Before we search for the global optimum, we must understand the behaviours of the piecewise
In addition, we also see that
On the other hand, the maximum of
If
The relative sizes of
0 ≤ c o s 𝜁 ≤ c o s ¯ 𝜁 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 , and𝐿 ≥ 0 . In𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 ,− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 is strictly increasing with a maximum point at‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ . Inc o s 𝜃 = c o s 𝜁 ,c o s 𝜁 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is strictly decreasing. However, if‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ , thenc o s 𝜁 > 1 for the entire range. We conclude that𝜇 = 𝛾 1 a r g m a x c o s 𝜃 ‖ 𝐯 ′ ‖ = m i n ( 1 , c o s 𝜁 ) , 𝜇 = 𝛾 1 0 ≤ c o s ¯ 𝜁 ≤ c o s 𝜁 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 , and𝐿 ≥ 0 . In𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 ,− 1 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is strictly decreasing with a maximum point at‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ . Inc o s 𝜃 = − 1 ,c o s ¯ 𝜁 ≤ c o s 𝜃 ≤ c o s 𝜁 . Therefore, we always have‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ a r g m a x c o s 𝜃 ‖ 𝐯 ′ ‖ = − 1 , 𝜇 = 𝛾 1 c o s 𝜁 ≤ 0 ≤ c o s ¯ 𝜁 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 , and𝐿 ≥ 0 . In𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 ,− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 is strictly increasing. In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ , the maximum occurs atc o s 𝜁 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 . This impliesc o s 𝜁 = 0 a r g m a x c o s 𝜃 ‖ 𝐯 ′ ‖ = 0 , 𝜇 = 𝛾 2 c o s ¯ 𝜁 ≤ 0 ≤ c o s 𝜁 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 , and𝐿 ≤ 0 . In𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 , we have− 1 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 ≤ c o s 𝜁 , which is strictly decreasing because‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ . Therefore, the maximum point is at𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 a r g m a x c o s 𝜃 ‖ 𝐯 ′ ‖ = { − 1 c o s ¯ 𝜁 > − 1 [ − 1 , 1 ] c o s ¯ 𝜁 ≤ − 1 𝜇 = 𝛾 1 c o s 𝜁 ≤ c o s ¯ 𝜁 ≤ 0 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 , and𝐿 ≤ 0 . In𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 ,− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 is strictly increasing. In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ ,c o s 𝜁 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 ≤ 0 is also strictly increasing. But since‖ 𝐯 ′ ‖ = ‖ 𝐯 𝜇 = 𝛾 2 ‖ at‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ = 0 , we conclude thatc o s 𝜃 = c o s ¯ 𝜁 a r g m a x c o s 𝜃 ‖ 𝐯 ′ ‖ = [ m a x ( − 1 , c o s ¯ 𝜁 ) , 1 ] , 𝜇 = 0 As we will see later, this case actually yields
, which is useless. But we will include this case for the sake of completeness.‖ 𝐯 ′ ‖ = ‖ 𝐯 ‖ c o s ¯ 𝜁 ≤ c o s 𝜁 ≤ 0 If and only if
,𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 ,𝐿 ≤ 0 . The rest of the analysis and the result are exactly the same as that in the𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 case.c o s ¯ 𝜁 ≤ 0 ≤ c o s 𝜁
Given the case-by-case study of these six permutations, we can summarise that the maximum point of
To implement (6.5), care must be taken when computing
6.3.2. Optimality¶
We show that the angles given in (6.5) actually gives the highest average acceleration over some time
Since the only variable is
where
On top of that, we also show that (6.5) gives the highest average speed over some time
Clearly (6.5) gives the maximum average speed because
where
6.3.3. Speed equations¶
Using (6.5) we obtain the optimal
For airstrafing where there is no friction (namely
These equations can be quite useful in planning. For example, to calculate the number of frames required to airstrafe from
In addition, under airstrafing again, we can integrate the speed equations to obtain distance-time equations. Before doing this, we must make a change of variables by assuming continuous time and writing
for each case.
For groundstrafing, however, the presence of friction means simple substitutions may not work. In more complex cases, it may be desirable to simply calculate the speeds frame by frame using the scalar FME.
6.3.4. Effects of frame rate¶
The frame rate can affect the acceleration significantly. Looking at the second case of (6.5), the acceleration per frame is
One can immediately see that the lower the
6.3.4.1. When 𝜂 ≠ 1 ¶
Recall in Frame rate that, on older game engines, the player frame rate
use a lower
such that𝜏 𝑔 (which would be𝜏 𝑝 = 𝜏 𝑔 or𝜏 𝑔 = 0 . 0 1 4 in the WON Blue Shift case), or𝑓 𝑔 ≈ 7 1 . 4 3 use
and𝜏 𝑔 = 1 / 7 2 in some of the frames and switch to𝜏 𝑝 = 0 . 0 1 3 in other frames𝜏 𝑝 = 𝜏 𝑔 = 0 . 0 1 4
We claim that it is better to always lower
Immediately, we can see that to maximise the average speed, we must have
Recall that
Observe that to maximise
6.3.5. Effects of friction¶
There is a limit to the speed achievable by maximum-acceleration groundstrafing alone. There will be a critical speed such that the increase in speed exactly cancels the friction, so that
Solving for
Take the case of default Half-Life settings at 1000 fps, we calculate
This is then the absolute maximum speed achievable by groundstrafing alone in vanilla Half-Life. At another common frame rate of 100 fps, we instead obtain the steady state speed of
Interestingly, when there is edge friction, the game sets
We also see that when the entity friction
Traditionally, jumping is done repeatedly to lift off from the ground to avoid the effects of ground friction. However, the presence of the bunnyhop cap (see Bunnyhop cap) compels speedrunners to opt for ducktapping (see Ducktapping) instead. Ducktapping has a downside of requiring one frame of ground contact, which introduces one frame of friction. The effect of this one frame of friction can be completely eliminated by setting the frame rate to an extremely high value in that frame alone, which forces
It turns out that the single frame of ground friction can be devastating, especially in lower frame rates. In fact, under most circumstances and combinations of movement variables, there exists a fixed point or steady state speed which acts as a limit to the speed a player can maintain indefinitely using only ducktapping and strafing alone. Let
Then
To give some concrete examples, consider ducktapping and strafing in a typical 1000 fps TAS with default Half-Life settings. Assuming
where
Assuming sv_maxvelocity at 1000 fps by ducktapping and strafing. Consider, however, ducktapping and strafing at 100 fps, which is a restriction some in the community are in favour of imposing. Here, (6.8) may instead be rewritten as
With
6.3.6. Growth of speed¶
By obtaining (6.7), we can immediately make a few important observations. In the absence of friction and if
for some
When
as long as
6.3.7. Air-ground speed threshold¶
The acceleration of groundstrafe is usually greater than that of airstrafe. It
is for this reason that groundstrafing is used to initiate bunnyhopping.
However, once the speed increases beyond
Fig. 6.2. Comparison between the accelerations arising from strafing in the air and on the ground at various speeds at default Half-Life settings and 1000 fps. Although the acceleration in the air is greater than that on the ground when the speed is very low, the acceleration in the air rapidly falls as speed increases. The air and ground accelerations cross later at the air-ground speed threshold of approximately 482 ups.¶
Analytic solutions for AGST are always available, but they are cumbersome to write and code. Sometimes the speed curves for airstrafe and groundstrafe intersects several times, depending even on the initial speed itself. A more practical solution in practice is to simply use Equation (6.1) to compute the new airstrafe and groundstrafe speeds then comparing them.
It is also important to note that, even if the air acceleration is greater than the ground acceleration for a given speed, it does not mean that it is optimal to actually leave the ground for air acceleration at that particular time. To illustrate, assume the default Half-Life settings and
On the other hand, the player could also ducktap or jump to get into the air and airstrafe, which would have yielded a speed of
We have
6.3.8. Effects of bunnyhop cap¶
It is impossible to avoid the bunnyhop cap (see Bunnyhop cap) when jumping in later official releases of the game. To lift off the ground and avoid the effects of ground friction, one alternative would be to ducktap instead (see Ducktapping). However, each ducktap requires the player to slide on the ground for one frame. Without using very high frame rates to force the frame to be
It turns out that the answer is not as straightforward as we may have thought and would require more investigations.
6.4. Maximum deceleration¶
It is often the case that the player needs to rapidly decelerate in the air or on the ground without any aid using weapons, damage, or solid entities. When the player is on the ground, deceleration is easy to achieve by simply issuing the +use command, which would exponentially reduce the velocity by a factor of 0.3 per frame. When the player is in the air, however, the player must rely on the pure air movement physics to decelerate as much as possible.
6.4.1. Arguments of the minima¶
Using the tools and partial results we built earlier in Maximum acceleration, we can perform a similar case-by-case analysis for the different permutations of
0 ≤ c o s 𝜁 ≤ c o s ¯ 𝜁 If
, then the minimum point is simply atc o s 𝜁 ≥ 1 sincec o s 𝜃 = − 1 for all𝜇 = 𝛾 1 .− 1 ≤ c o s 𝜃 ≤ 1 Suppose
andc o s 𝜁 < 1 . Then,c o s ¯ 𝜁 > 1 is strictly decreasing in‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ , so we must consider the pointsc o s 𝜁 ≤ c o s 𝜃 ≤ 1 . We show that the global minimum is still atc o s 𝜃 = ± 1 . Calculate the local minima atc o s 𝜃 = − 1 andc o s 𝜃 = − 1 :c o s 𝜃 = 1 ‖ 𝐯 ′ ( c o s 𝜃 = − 1 ) ‖ = ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ ‖ 𝐯 ′ ( c o s 𝜃 = 1 ) ‖ = 𝐿 Suppose the minimum point is at
. This impliesc o s 𝜃 = 1 ‖ 𝐯 ′ ( c o s 𝜃 = 1 ) ‖ ≤ ‖ 𝐯 ′ ( c o s 𝜃 = − 1 ) ‖ 𝐿 ≤ ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ Assume
. Then this implies‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 𝐿 + 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ ‖ 𝜆 ( 𝐯 ) ‖ which is a contradiction, because our supposition that
impliesc o s ¯ 𝜁 > 1 . Assume instead that‖ 𝜆 ( 𝐯 ) ‖ < 𝐿 . Then we obtain‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 − ( 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ) ≥ ‖ 𝜆 ( 𝐯 ) ‖ But
implies0 ≤ c o s 𝜁 and clearly𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 , which is a contradiction. This concludes the proof.‖ 𝜆 ( 𝐯 ) ‖ ≥ 0 Suppose
. Then inc o s 𝜁 ≤ c o s ¯ 𝜁 ≤ 1 ,− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 is strictly increasing with a minimum point at‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ . Inc o s 𝜃 = − 1 ,c o s 𝜁 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is strictly decreasing with a minimum point at‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ and a minimum value ofc o s 𝜃 = c o s ¯ 𝜁 corresponding to‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ . In𝜇 = 0 , the value stays atc o s ¯ 𝜁 ≤ c o s 𝜃 ≤ 1 . We show that the global minimum is yet again at‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ . Calculate the local minima corresponding toc o s 𝜃 = − 1 andc o s 𝜃 = − 1 . We havec o s 𝜃 ∈ [ c o s ¯ 𝜁 , 1 ] ‖ 𝐯 ′ ( c o s 𝜃 = − 1 ) ‖ = ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ ‖ 𝐯 ′ ( c o s 𝜃 ∈ [ c o s ¯ 𝜁 , 1 ] ) ‖ = ‖ 𝜆 ( 𝐯 ) ‖ Suppose the global minimum is at
. This impliesc o s 𝜃 ∈ [ c o s ¯ 𝜁 , 1 ] ‖ 𝜆 ( 𝐯 ) ‖ ≤ ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ Assume
. Then we obtain‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 0 ≥ 𝑘 𝑒 𝜏 𝑀 𝐴 which is a contradiction. Assume instead that
, which implies‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 ‖ 𝜆 ( 𝐯 ) ‖ ≤ 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 But
impliesc o s ¯ 𝜁 ≤ 1 . Putting these inequalities together yields𝐿 ≤ ‖ 𝜆 ( 𝐯 ) ‖ 𝐿 − 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 Since
and𝐿 ≥ 0 , this further implies that𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 < 𝐿 − 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 But
implies0 ≤ c o s 𝜁 , which is a contradiction. This concludes the proof.𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 We conclude that
a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = − 1 0 ≤ c o s ¯ 𝜁 ≤ c o s 𝜁 In
,− 1 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is strictly decreasing. In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ , we havec o s ¯ 𝜁 ≤ c o s 𝜃 ≤ 1 . If‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ , the minimum point is atc o s ¯ 𝜁 > 1 becausec o s 𝜃 = 1 is strictly decreasing. We conclude that‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = [ m i n ( 1 , c o s ¯ 𝜁 ) , 1 ] c o s 𝜁 ≤ 0 ≤ c o s ¯ 𝜁 Suppose
andc o s 𝜁 < − 1 . Thenc o s ¯ 𝜁 > 1 for all‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ . Since− 1 ≤ c o s 𝜃 ≤ 1 is an even function in‖ 𝐯 ′ 𝜇 = 𝛾 2 , we havec o s 𝜃 a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = { − 1 , 1 } Suppose
andc o s 𝜁 ≥ − 1 . Thenc o s ¯ 𝜁 > 1 is strictly increasing in‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ , therefore there are also two local minima at− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 andc o s 𝜃 = − 1 . We claim that the global minimum is atc o s 𝜃 = 1 . Suppose the contrary, that is the global minimum is atc o s 𝜃 = − 1 . This impliesc o s 𝜃 = 1 ‖ 𝐯 ′ 𝜇 = 𝛾 2 ( c o s 𝜃 = 1 ) ‖ ≤ ‖ 𝐯 ′ 𝜇 = 𝛾 1 ( c o s 𝜃 = − 1 ) ‖ 𝐿 ≤ ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ Assume
. Then we have‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 𝐿 + 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ ‖ 𝜆 ( 𝐯 ) ‖ But
impliesc o s ¯ 𝜁 ≥ 1 . Putting these inequalities together yields‖ 𝜆 ( 𝐯 ) ‖ ≤ 𝐿 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 This contradicts
. Assume instead thatc o s 𝜁 ≤ c o s ¯ 𝜁 . Then we have‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 − ( 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ) ≥ ‖ 𝜆 ( 𝐯 ) ‖ But
implies that− 1 ≤ c o s 𝜁 ≤ 0 , which is a contradiction. This concludes the proof.| 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 | = − ( 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ) ≤ ‖ 𝜆 ( 𝐯 ) ‖ Suppose
andc o s 𝜁 < − 1 . Inc o s ¯ 𝜁 ≤ 1 ,− 1 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 . In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ , we simply havec o s ¯ 𝜁 ≤ c o s 𝜃 ≤ 1 . We claim that the global minimum is always at‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ . Suppose the contrary, that the global minimum is atc o s 𝜃 = − 1 . This implies thatc o s 𝜃 ∈ [ c o s ¯ 𝜁 , 1 ] ‖ 𝜆 ( 𝐯 ) ‖ ≤ ‖ 𝐯 ′ 𝜇 = 𝛾 2 ( c o s 𝜃 = − 1 ) ‖ = 𝐿 This contradicts the assumption that
from which we deduce thatc o s ¯ 𝜁 ≤ 1 . End of proof.‖ 𝜆 ( 𝐯 ) ‖ ≥ 𝐿 Finally, suppose
andc o s 𝜁 ≥ − 1 . Then we again claim that the global minimum occurs atc o s ¯ 𝜁 ≤ 1 . Suppose the contrary, that the global minima occur atc o s 𝜃 = − 1 . Then this implies thatc o s 𝜃 ∈ [ c o s ¯ 𝜁 , 1 ] ‖ 𝜆 ( 𝐯 ) ‖ ≤ ‖ 𝐯 ′ 𝜇 = 𝛾 1 ( c o s 𝜃 = − 1 ) ‖ = ∣ ‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ∣ Assume that
. Then we have‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≥ 0 ≥ 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 which contradicts
. Assume otherwise thatc o s 𝜁 ≤ c o s ¯ 𝜁 . Then we obtain‖ 𝜆 ( 𝐯 ) ‖ − 𝑘 𝑒 𝜏 𝑀 𝐴 ≤ 0 ‖ 𝜆 ( 𝐯 ) ‖ ≤ 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 On the other hand,
impliesc o s 𝜁 ≥ − 1 − ( 𝐿 − 𝑘 𝑒 𝜏 𝑀 𝐴 ) ≤ ‖ 𝜆 ( 𝐯 ) ‖ 𝐿 ≥ 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 But
also impliesc o s ¯ 𝜁 ≤ − 1 ‖ 𝜆 ( 𝐯 ) ‖ ≥ 𝐿 ≥ 1 2 𝑘 𝑒 𝜏 𝑀 𝐴 which is a contradiction. End of proof.
We conclude that
a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = { { − 1 , 1 } c o s 𝜁 < − 1 ∧ c o s ¯ 𝜁 > 1 − 1 c o s 𝜁 ≥ − 1 ∨ c o s ¯ 𝜁 ≤ 1 c o s ¯ 𝜁 ≤ 0 ≤ c o s 𝜁 In
,− 1 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is strictly decreasing. In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ ,c o s ¯ 𝜁 ≤ c o s 𝜃 ≤ 1 . We conclude that‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = [ m a x ( − 1 , c o s ¯ 𝜁 ) , 1 ] c o s 𝜁 ≤ c o s ¯ 𝜁 ≤ 0 In
,− 1 ≤ c o s 𝜃 ≤ c o s 𝜁 is strictly increasing. In‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 1 ‖ ,c o s 𝜁 ≤ c o s 𝜃 ≤ c o s ¯ 𝜁 is also strictly increasing and ends with‖ 𝐯 ′ ‖ = ‖ 𝐯 ′ 𝜇 = 𝛾 2 ‖ at‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ . Inc o s 𝜃 = c o s ¯ 𝜁 , we havec o s ¯ 𝜁 ≤ c o s 𝜃 ≤ 1 . We conclude that‖ 𝐯 ′ ‖ = ‖ 𝜆 ( 𝐯 ) ‖ a r g m i n c o s 𝜃 ‖ 𝐯 ′ ‖ = { − 1 c o s ¯ 𝜁 > − 1 [ − 1 , 1 ] c o s ¯ 𝜁 ≤ − 1 c o s ¯ 𝜁 ≤ c o s 𝜁 ≤ 0 The analysis and result is exactly the same as that in the
case.c o s ¯ 𝜁 ≤ 0 ≤ c o s 𝜁
Combining the above case-by-case findings, we have the global minimum at
6.4.2. Effects of frame rate¶
In every case in (6.9), the frame rate has no effect on the deceleration if we ignore the effects of friction. For example, suppose
Assuming
which is independent of the frame rate.
6.5. Speed preserving strafing¶
Speed preserving strafing can be useful when we are strafing at high sv_maxvelocity. Occasionally, this can prove cumbersome as the curvature decreases with increasing speed, making the player liable to collision with walls or other obstacles. Besides, as the velocity gradually becomes parallel to one of the global axes again, the speed will drop back to sv_maxvelocity. This means, under certain situations, that the slight speed increase in the process of making the turn has little benefit. Therefore, it can sometimes be helpful to simply make turns at a constant sv_maxvelocity. This is where the technique of speed preserving strafing comes into play. Another situation might be that we want to groundstrafe at a constant speed. When the speed is relatively low, constant speed groundstrafing can produce a very sharp curve, which is sometimes desirable in a very confined space.
We first consider the case where friction is absent. Setting
If
At this point we can go ahead and write out the full formula for
On the other hand, if friction is present, then we have
By the usual line of attack, we force
and the necessary condition
We can check that if friction is absent, then
Note that we took the negative square root, because
Observe that we need
Note that, regardless of whether friction is present, if
6.6. Curvature¶
The locus of a point obtained by strafing is a spiral. Intuitively, at any given speed there is a limit to how sharp a turn can be made without lowering acceleration. It is commonly known that this limit grows harsher with higher speed. As tight turns are common in Half-Life, this becomes an important consideration that preoccupies speedrunners at almost every moment. Learning how navigate through tight corners by strafing without losing speed is a make-or-break skill in speedrunning.
It is natural to ask exactly how this limit can be quantified for the benefit of TASing. The simplest way to do so is to consider the radius of curvature of the path. Obviously, this quantity is not constant with time, except for speed preserving strafing. Therefore, when we talk about the radius of curvature, precisely we are referring to the instantaneous radius of curvature, namely the radius at a given instant in time. But time is discrete in Half-Life, so this is approximated by the radius in a given frame.
6.6.1. 90 degrees turns¶
Passageways in Half-Life commonly bend perpendicularly, so we frequently make 90 degrees turns by strafing. We intuitively understand how the width of a passage limits the maximum radius of curvature one can sustain without colliding with the walls. This implies that the speed is limited as well. When planning for speedruns, it can prove useful to be able to estimate this limit for a given turn without running a simulation or strafing by hand. In particular, we want to compute the maximum speed for a given passage width.
Fig. 6.3. A common 90 degrees bend in the On A Rail chapter in Half-Life. Shown in this
figure is one such example in the map c2a2e. In an optimised speedrun,
the player would be moving extremely fast in this section due to an earlier
boost.¶
Fig. 6.4. Simplifying model of a common scenario similar to the one shown in Fig. 6.3..¶
We start by making some simplifying assumptions that will greatly reduce the
difficulty of analysis while closely modelling actual situations in practice.
Referring to Fig. 6.4., the first assumption we make is
that the width of the corridor is the same before and after the turn. This width
is denoted as
By trivial applications of the Pythagorean theorem, it can be shown that the relationship between the radius of curvature
This formula may be used to estimate the maximum radius of curvature for making such a turn without collision. However, the radius of curvature by itself is not very useful. We may wish to further estimate the maximum speed corresponding to this
6.6.2. Radius-speed relationship¶
The following figure depicts the positions of the player at times
Based on the figure, the radius of curvature may be approximated as the
Note that this is the most general formula, applicable to any type of strafing. From this equation, observe that the radius of curvature grows with the square of speed. This is a fairly rapid growth. On the other hand, under maximum speed strafing, the speed grows with the square root of time. Informally, the result of these two growth rates conspiring with one another is that the radius of curvature grows linearly with time. We also observe that the radius of curvature is directly influenced by
From Equation (6.10) we can derive formulae for various types of strafing by eliminating
Or, solving for
For Type 1 strafing, the formula is clumsier. Recall that we have
To eliminate
Then we proceed by substituting, yielding
We cannot simplify this equation further. In fact, solving for