SA-MP Forums Archive
Detect if vehicle moving or not. - 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: Detect if vehicle moving or not. (/showthread.php?tid=660253)



Detect if vehicle moving or not. - ZigGamerx - 28.10.2018

Anyone knows how to detect that 'is vehicle moving or not?'


Re: Detect if vehicle moving or not. - RogueDrifter - 28.10.2018

Код:
#define SPEED_OF_MOVING 3

GetVehicleSpeed(vehicleid)
{
    new Float:ST[4];
    GetVehicleVelocity(vehicleid,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]);
}

bool:IsVehicleMoving(vehicleid) return (GetVehicleSpeed(vehicleid) > SPEED_OF_MOVING);
I don’t claim credit for the vehicle speed function.


Re: Detect if vehicle moving or not. - Calisthenics - 28.10.2018

Speed will be 0 when all three axes are 0 so the calculation of square root is meaningless.