GetVehicleVelocity problem?
#1

Hi,
I have the following formula to calculate the speed of a vehicle (km/h):

Код:
new Float:v, Float:x, Float:y, Float:z;
GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);
v = floatround((x + y + z) / 0.003, floatround_floor);
It doesn't work perfectly, I think.
Can anybody help me?
Reply
#2

pawn Код:
stock Float:GetPlayerSpeed(playerid)
{
    new
      Float:vX,
      Float:vY,
      Float:vZ;
    if (!IsPlayerInAnyVehicle(playerid))
    {
      GetPlayerVelocity(playerid, vX, vY, vZ);
    }
    else
    {
      GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
    }
    return floatsqroot(vX*vX + vY*vY + vZ*vZ);
}
I found that function, it seems to work.
Reply
#3

Thanks!
Is it in KM/U?
Reply
#4

I don't really know, I didn't make the function. If you want KPH, use this function:

pawn Код:
stock Float:GetVehicleSpeed(vehicleid,UseMPH = 0)
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:te mp_speed;
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed _z);
if(UseMPH == 0)
{
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+ (speed_z*speed_z))*136.666667;
} else {
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+ (speed_z*speed_z))*85.4166672;
}
floatround(temp_speed,floatround_round);return temp_speed;
}
Reply
#5

Thank you!!!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)