8. Surfing and wallstrafing

Surfing is a very specialised technique in Half-Life that is crucial in surf maps. The act of surfing involves accelerating against a sloped wall, thereby allowing some control over the vertical position of the player that is not possible by pure strafing alone. On the other hand, wallstrafing refers to the act of accelerating against a vertical wall, ideally with as much horizontal acceleration as possible.

While these two techniques are seemingly different, at least in their objectives, wallstrafing can be considered a degenerative case where the wall is perfectly vertical rather than sloped. The techniques for analysis is somewhat similar for the two cases, at least for the simplest cases, therefore we will discuss the two techniques in the same chapter.

8.1. Wallstrafing

Note

TODO: reword

The collision equation is

where is the velocity produced by the FME. Assuming , the speed is given by

On the other hand, from the FME we have

where is the rotation matrix. Performing dot product with the plane normal gives

Assuming the initial velocity lies on the plane, we have . On the other hand, because is being rotated out of the collision plane by radians. It follows that the angle between the rotated and must be , or

As usual, the speed as a result of the FME is given by

Substituting back to the collision equation and simplifying yields

Let , then we can see that the speed is strictly decreasing in .

Similarly, let , setting the derivative to zero and simplifying, we obtain,

It can be shown that

gives the maximum of the function.

Note

TODO: more commentary

8.2. Pure sliding

Pure sliding turns out to be one of the fastest ways to gain horizontal speed down a sloped wall. One gains horizontal speed much faster asymptotically than strafing. This is not surprising when we consider the fact that the horizontal speed due to strafing increases roughly in proportion to the square root of time. By sliding down a plane, however, both the horizontal and vertical speed can potentially increase linearly with time, or constant acceleration.

Recall from the general collision equation (GCE) (see Collision) that

where is the speed due to strafing and gravity and is the assumed bounce coefficient. If no strafing is performed, we simply have

where is in the first frame and for subsequent frame, to account for the leapfrog integrated gravitational field, as described in Gravity. To compute the GCE, we need to compute the dot product . Assuming the initial velocity lies on the plane, then . If the plane normal makes an angle of with the horizontal plane, then we can write . What remains is therefore

Eliminating the dot product and from the GCE yields

Here we can see that

while the horizontal speed is

where , , and is the angle between the projected velocity on the horizontal plane and the projected plane normal . In the worst case where , the horizontal speed increases roughly square root with time, but not for long, because gradually decreases over time as the component of velocity in the direction of the plane normal accelerates. In the best case where , the expression simplifies to

That is, the horizontal speed accelerates linearly with time. This is also the steady state expression as drifts towards zero over time.

8.3. Vertical balance surfing

Before tackling the harder issues on surfing, let’s tackle a basic movement strategy. When surfing on a slope, one can move vertically up or down depending on the strafing angle . There must exist a critical such that the vertical velocity will remain zero throughout, resulting in no vertical movement. As we shall see later, the horizontal speed would usually increase as usual, though at a lower acceleration than pure strafing.

In the GCE, the velocity is due to the fundamental movement equation (FME) (described in detail in Air and ground movements) added to the gravitational step. Namely,

A few notes to be made here. First, is a three-dimensional vector here, unlike the vectors in a typically written FME. Therefore, the rotation matrix is specifically a rotation about the axis, written as . Second, means a diagonal matrix with entries . By multiplying a vector with , for example, we effectively zero out the and components. Indeed, the horizontal acceleration portion is multiplied by because the vertical component of the velocities are ignored in strafing and horizontal acceleration in general. Third, the gravity time step has a , which has a value of for the first frame and for subsequent frames.

We now substitute into the GCE. To compute the GCE, we perform the dot product . The first term from the product may be written as

Assume that the initial velocity lies on the plane, which makes . Now because the velocity vector is being rotated away or into the plane. It follows that the angle between the two vectors is when projected onto the horizontal plane. The absolute value of must be taken because the strafing angle can be negative. On the other hand, note that the plane normal projected onto the horizontal plane is no longer a unit vector, but rather, a vector of length where is the angle between the plane normal and the horizontal plane.

Using these observations, we find that the first term is equivalent to

The second term is easier to find. It is simply

From the GCE, the final vertical velocity is given by

Assume that , which is the steady state where no vertical movement occurs, the equation simplifies to

This assumes , which holds as long as the plane is not horizontal. Here, the usual analysis can be performed by assuming or and proceed to solve the equation. Empirical observations indicate that is most frequently the admissible solution. Unfortunately, as is common in surfing analysis, writing down the solutions analytically is very difficult because it requires finding the roots of a quartic polynomial. It is much more practical to use a robust numerical method such as Brent’s method to find a solution, or by computing the eigenvalues of the associated companion matrix.

8.4. Maximum per-frame horizontal acceleration

This section describes an attempt to optimise the horizontal acceleration on a surf plane. This approach involves maximising the horizontal acceleration on a per-frame basis. That is, this approach only considers the current frame without accounting for the acceleration in future frames. In isolation, as it turns out, it does not give us a global optimum. This serves to illustrate the danger of thinking in per-frame terms as is common in pure strafing, where, by luck, per-frame optimisations happen to also yield a global optimum. Attempting to maximise the accelerate per frame is a greedy algorithm, which in general is not guaranteed to give the most optimal configurations.

To illustrate this point, we will not derive an analytical expression for per-frame maximum acceleration. It suffices to use a numerical algorithm on a common Half-Life configuration, which consists of , (for 100 fps), , and a surf plane of such that . Assume an initial velocity of . One can check that the velocity and the plane normal are perpendicular.

8.5. Minimal time path