Strafe jumping math. A simplistic explanation - nsavch/xanmel GitHub Wiki

Note: this is is an (over)-simplified explanation, lacking any mathematical strictness. If you are familiar with vectors and operations with them, skip first three sections.

1. Vectors

The most basic concept for this article is the definition of vector. Vector is something that has size (absolute value) and direction. For example, speed is a vector - it has a numerical value (like 60 mph) and a direction where the thing moves. Values without directions are called scalars. For example, weight is a scalar, while it has a numerical value it's not directed anywhere.

2. Vector addition

Vectors can be added one to another. A sum of vectors is another vector, pointing between the two summed vectors. The absolute value of the result depends on the values of items and the angle between them. The lower the angle is, the bigger will be the value of the result.

Imagine a heavy box which you and your friend are pushing. If you both push it in one direction, the forces which you apply will just sum up. If you push into different directions, then the resulting force will be lower and will be directed in the middle between the applied directions.

Fig 1. A graphical representation of a vector sum. Vectors a and b added one to another

3. Vector projections

Imagine a situation when you are going to a grocery store. Suddenly you notice a pretty girl, and change your direction towards her. Let's think if you are still getting closer to the store, and how fast are closing to (or moving away from) it.

If the girl and the store are located at the same direction, then of course the speed of your approach to the store won't change. But if there is an angle between the direction to the girl and the direction to the store, then your speed towards the store will decrease. If the angle is 90 degrees, then you won't be closing to the store at all, and if the angle is more than 90 degrees then you'll walk away from the store.

Fig 2. Projecting a speed vector to another direction. If the angle between the original direction, and the projection direction is low, then the value of the projected vector is almost the same as the value of the original vector. If the angle is high, then the value of the projection will be almost zero.

4. Velocity and acceleration

As we mentioned earlier, speed is a vector. It has a value and a direction. So there are two ways of how the speed can be changed - direction change and value change. Both the direction and the value can be changed at the same time, or one of them can stay the same. The difference of the speed change per some time period is called acceleration. As the acceleration has its own direction and value, it's also a vector. So knowing the initial speed and the acceleration we can easily calculate the resulting speed using the vector sum operation we defined earlier:

Adding some acceleration. Note that the resulting speed v' turned bit right compared to the original speed v. This means that the moving thing won't go straight, but start turning.

5. Vectors in Quake

All quake characters can move in any direction - that's why we love that game. So as you could guess, the speed of each character is a vector. Also the speed constantly changes (both its value and direction), so the player has got an acceleration vector as well. Each player has also a looking direction, which isn't always the same as the speed direction, as you can look around while flying without changing your speed.

The looking direction is controlled by the mouse, the acceleration is controlled by the WASD keys. The speed isn't directly controlled by the player, but is rather calculated using the provided acceleration and looking direction.

All possible accelerations you can apply with a fixed looking direction. You can accelerate in 8 directions. The absolute value is the same for all 8 directions.

6. Restrictions of the Quake Engine

The quake engine has an interesting system of restricting player velocity. It has no hard limit for the speed, but applies acceleration which the player requests only if a specific condition is met. The condition is simple, and it's very important to understand it. The acceleration is applied ONLY if the value of the speed projection on the acceleration direction is lower than the maximum speed (320 qu/s in original quake 3, 360 qu/s in cpm/xonotic). If the velocity direction and the acceleration direction are the same you can just accelerate to 360 qu/s and no more. But if the directions differ that's when interesting things happen.

Fig 5. In case of W-only bunny hopping the acceleration direction and moving direction are the same. So the speed projection on the acceleration direction has the same value as the original speed. So when you reach max speed, no acceleration is applied. In case of W+D strafe jumping there is a big angle between velocity direction and acceleration direction, so even if the speed is higher than the max speed, its projection max be lower than the max value, and the acceleration is applied.

Fig 6. D-strafe accel, which most players use on slick maps.

7. Exploiting the restrictions

Well, shouldn't be it obvious how the restriction can be exploited? The idea is to apply your acceleration into a proper direction, to keep the velocity projection on the acceleration direction below 320/360 qu/s. How to maintain such an acceleration is a topic of further discussion.