Vehicle velocity

Everything you need to know when working with vehicle velocities can be found here.

Why this page?

We noticed server developers have been debating for almost a decade about how to properly calculate vehicle speeds using values from GetVehicleVelocity. We felt it necessary to join in on this "debate" and answer it properly, using our knowledge about the game's code. It has been known for a very long time that the correct way to calculate the speed of a vehicle is to get the magnitude of the velocity vector returned by GetVehicleVelocity. One thing has long been missing though - a so-called "magic value". The magnitude of the velocity vector has to be multiplied with this value in order to find the actual in-game speed.

The magic value

In GTA: SA, the magic value is 180.0, as many people already suspected. This is what R* uses, and, we recommend you to do the same, that-is, if you want to stay accurate to what R* uses.

So, is this it? Should we all just use 180.0?

Yes, and no. As said, if you want to stay accurate to what R* uses, then yes. Since people have (rightfully) pointed out that the vehicle speeds reported may not be entirely accurate, or not quite what you'd expect, you might want to use your own arbitrary logic which works well for you. We plan on adding server-side vehicle handling in the future (if possible), however, which changes the discussion entirely.

Server-side vehicle handling? Why would that change anything?

Yes, server-side vehicle handling. It will essentially give you full control over all of the handling.cfg settings on a server-wide basis. This includes the vehicle top speed. By that point, any arbitrary logic outside of what R* uses would be considered as bad practice, as we deem the handling data itself as a culprit. Why would you need arbitrary logic (or a different "magic value") by that point? Hint: you don't. Now, of course, this is all talk about an upcoming UG-MP feature, so for now, it's best to just use whatever works best for you.

Factors affecting the top speed

There are numerous factors which affect a vehicle's possible top speed. Here are a few of them:

  • Culling zones: Culling zones are special zones placed on the map which can have a number of possible attributes. One of them restricts the vehicle's top speed. It is used on long stretches of roads (e.g. the San Fierro bridges).
  • The surface the vehicle is on: It should come as no surprise that certain surfaces affect the vehicle's traction (and possibly the top speed).
  • There may be other factors which affect the possible top speed as well. To this day, they are not yet properly known.

It should be noted that nitro does not affect the possible top speed of a vehicle. Nitro only affects acceleration.

How we recommend doing it

The below example shows how R* calculates the vehicle top speed (excluding the above mentioned logic which is still unknown):

#define VEHICLE_SPEED_MULT 180.0

VectorMagnitude(Float:x, Float:y, Float:z)
    return floatsqroot(x * x + y * y + z * z);

    new Float:x, Float:y, Float:z;

    GetVehicleVelocity(vehicleid, x, y, z);

    return VectorMagnitude(x, y, z) * VEHICLE_SPEED_MULT;