GetVehicleVelocity problem? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetVehicleVelocity problem? (
/showthread.php?tid=357867)
GetVehicleVelocity problem? -
Superthijs - 08.07.2012
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?
Re: GetVehicleVelocity problem? -
coole210 - 08.07.2012
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.
Re: GetVehicleVelocity problem? -
Superthijs - 08.07.2012
Thanks!
Is it in KM/U?
Re: GetVehicleVelocity problem? -
coole210 - 08.07.2012
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;
}
Re: GetVehicleVelocity problem? -
Superthijs - 08.07.2012
Thank you!!!