26.12.2013, 22:47
I was wondering how one can calculate speed of a vehicle? I have searched a bit on the forums, watched and read source of speedometers but I don't really understand. I have gone through a bit with "GetVehicleVelocity" function on SA-MP wiki but I don't really understand, what does it give? Does it give the value that it takes one meter/unit (ingame), as in does it give the time that it takes for the vehicle to move 1 unit? A brief explaination would be nice. :S
I did also search on the forums and this forumla came up:
Same as in another tutorial:
Where speed_n or svn[playerid] (where n is either x, y or z) are from the function GetVehicleVelocity. I can see that they have basically taken the length of a vector (absolute value) or well basically the absolute value of whatever is given in GetVehicleVelocity and then multiplied with a number which I am guessing is "the magic number" referred to this thread.
Yet my main problem is that I don't understand this, why to use the absolute value (wiki it if you wonder what "absolute value" means) and my other or well first problem is what GetVehicleVelocity -actually- gives for a value, what is it? Is it a vector or something that is given per second or per unit or something?
I did also search on the forums and this forumla came up:
Код:
s1[playerid] = floatsqroot(((svx[playerid]*svx[playerid])+(svy[playerid]*svy[playerid]))+(svz[playerid]*svz[playerid]))*100;
Код:
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
Yet my main problem is that I don't understand this, why to use the absolute value (wiki it if you wonder what "absolute value" means) and my other or well first problem is what GetVehicleVelocity -actually- gives for a value, what is it? Is it a vector or something that is given per second or per unit or something?