ACCURATE and CORRECT GetVehicleSpeed with MPH and KM/H
#1

I need an ACCURATE and CORRECT GetVehicleSpeed function that can return both MILES PER HOUR and KILOMETRES PER HOUR speeds. Obviously it needs to use GetVehicleVelocity.

I have searched for hours and only found bad ones that aren't accurate.

Thank you.
Reply
#2

The only way to make a correct one is to make it for each vehicle. There is no magic number to make it accurate for all vehicles, GTA SA vehicles weren't made with the speed limits they have in real life.
Reply
#3

You can get the M/S (meters/units per second) in-game. You can covert that to miles per hour or KM/H. It's do-able.
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
You can get the M/S (meters/units per second) in-game. You can covert that to miles per hour or KM/H. It's do-able.
I'll say it in different words.

GTA SA vehicles do NOT have the same maximum speeds as in real life. There is NO way you can calculate it accurate for each vehicle without making calculations specific for that vehicle.

While one car drives faster ingame than in real life, another may drive slower ingame than in real life.
Reply
#5

Who said anything about top speeds or real life speeds? I certainly didn't.
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
Who said anything about top speeds or real life speeds? I certainly didn't.
The only thing you certainly didn't do is use your brain.

If the top speeds aren't accurate, then neither is any other speed. seriously.
Reply
#7

Here's this one, works like a charm.
pawn Код:
stock GetPlayerSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 179.28625;
    return floatround(ST[3]);
}
Reply
#8

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
The only thing you certainly didn't do is use your brain.

If the top speeds aren't accurate, then neither is any other speed. seriously.
The max speeds aren't accurate because Rockstar didn't set them to be. I need a speed function based on an OBJECT's (a vehicle) velocity (METERS (units) PER SECOND). The calculation would be EXACTLY the same for working out the MPH of an object being moved with MoveObject(). It has NOTHING to do with max speeds or vehicles.

The only way in which you could be right is if the GetVehicleVelocity function is inaccurate, but from what I know it is not. Even so, the old GetDistanceBetweenPoints method could be used (with the equation 'Speed = Distance/Time').



Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
Here's this one, works like a charm.
pawn Код:
stock GetPlayerSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 179.28625;
    return floatround(ST[3]);
}
Quote:
Originally Posted by MP2
Посмотреть сообщение
I need an ACCURATE and CORRECT GetVehicleSpeed function that can return both MILES PER HOUR and KILOMETRES PER HOUR speeds. Obviously it needs to use GetVehicleVelocity.

I have searched for hours and only found bad ones that aren't accurate.

Thank you.
What is the '179.28625' for?
Reply
#9

Quote:
Originally Posted by MP2
Посмотреть сообщение
I need a speed function based on an OBJECT's (a vehicle) velocity (METERS (units) PER SECOND). The calculation would be EXACTLY the same for working out the MPH of an object being moved with MoveObject(). It has NOTHING to do with max speeds or vehicles.


What is the '179.28625' for?
Then why do you keep implying that most GetVehicleSpeed functions are inaccurate? There are enough of them around which use the velocity, yet you say they are inaccurate. Even though they use the exact method described by you. Weird, don't you think?
If you want the accurate speed, calculate it without 'magic number', you'll get the exact speed the vehicle is driving. But are they accurate in relation to the actual world? No. Even though you'll have an accurate function, your cars will be driving unrealistic speeds.

And for the '179.28625', that's the magic number you need to turn the 'accurate velocity speeds' into 'accurate real life speeds'. The problem is, and I've explained it before, is that there is no magic number that works for ALL vehicles.

You can keep on searching all you want. Until you do what I told you in the first reply, you won't have an accurate speed function.
Reply
#10

So what you're basically saying is, the units in the game are NOT equal to a real life meter? Well that's pretty darn easy to solve. Or are you saying GetVehicleVelocity is wrong?

Obviously I made this topic as I haven't got the skills to make this myself. That being said, I did Physics GCSE and therefore know a little bit about velocity and speed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)