first of all then you need the more advanced maths of the Velocity family
then you need to consider in what type your formulat give the answers: degrees or radians? (however conversion is fairly simple)
And I would like to say that GetVehicleVelocity has nothing to do with time but I know that this is not true however very hard to prove here as it comes to Headings, Directions and Speeds in just 3 variables (X, Y ,Z) which can be negative too. And speed is ALWAYS related to distance and time.
I actually prepared a test:
pawn Код:
#include <a_samp>
new
Float:X[4][MAX_PLAYERS],
Float:Y[4][MAX_PLAYERS],
Float:Z[4][MAX_PLAYERS],
time_start[MAX_PLAYERS] = {0,...},
time_end[MAX_PLAYERS] = {0,...},
Float:distance[4][MAX_PLAYERS];
#define p(%1) %1[playerid]//ye I know I am lazy...
public OnPlayerUpdate(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
GetVehiclePos(vehicleid,p(X[0]),p(Y[0]),p(Z[0]));
p(distance[0]) = GetDistance(p(X[0]),p(Y[0]),p(Z[0]),p(X[1]),p(Y[1]),p(Z[1]));
time_start[playerid] = GetTickCount();
GetVehicleVelocity(vehicleid,p(X[2]),p(Y[2]),p(Z[2]));
p(distance[2]) =
floatsqroot
(
floatpower(p(X[2]),2)
+
floatpower(p(Y[2]),2)
+
floatpower(p(Z[2]),2)
)
;
printf("Distance traveled: %f, velocity that should be equal: %f, Time passed since last update: %dms",distance[0],distance[2],time_start[playerid]-time_end[playerid]);
printf("Old Distance traveled: %f, Old velocity that should be equal: %f",distance[1],distance[3]);
p(X[1]) = p(X[0]),
p(Y[1]) = p(Y[0]),
p(Z[1]) = p(Z[0]),
p(X[3]) = p(X[2]),
p(Y[3]) = p(Y[2]),
p(Z[3]) = p(Z[2]),
p(distance[1]) = p(distance[0]),
p(distance[3]) = p(distance[2]);
time_end[playerid] = time_start[playerid];
return 1;
}
#undef p
forward Float:GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 );
stock Float:GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
return floatsqroot
(
(
(
x1 - x2
)
*
(
x1 - x2
)
)
+
(
(
y1 - y2
)
*
(
y1 - y2
)
)
+
(
(
z1 - z2
)
*
(
z1 - z2
)
)
)
;
}
I have written it RAW even without compilation, it's 1:10 AM, there CAN be errors or this can be totally incorrect!
I have found this:
Definition 2: Velocity
Velocity is the rate of change of position vector with respect to time and is expressed as the ratio of change in position vector and time.