16.07.2015, 01:06
(
Последний раз редактировалось BCG2000; 19.07.2015 в 09:46.
)
EDIT: I decided to edit my post, also adding SetVehicleLocalXYVelocity (I know it has been done plenty of times before under other names but I made this one to be used with GetVehicleLocalXYVelocity, this mean that it is in some way different from other functions of its type, letting you set X and Y local velocity at the same time, instead of just forward/backward as it commonly is).
Functions:
With these functions you can set and get how fast the vehicle is going forward/backward and on the sides, might be useful for drift calculations and other vehicle velocity related scripts. Using both together you can have precise velocity control based on the vehicle's Z rotation angle.
Example:
Yes, simple as that! Enjoy.
EDIT2: Functions optimized, thanks to Nero_3D.
Functions:
Код:
stock SetVehicleLocalXYVelocity(vehicleid, Float:VelocityX, Float:VelocityY) { // FUNCTION: Set the local XY velocity of the specified vehicle (velocity relative to its Z rotation angle). new Float:VSpeed[3], Float:VRotZ; GetVehicleVelocity(vehicleid, VSpeed[0], VSpeed[1], VSpeed[2]); GetVehicleZAngle(vehicleid, VRotZ); // Optimized, thanks to Nero_3D. SetVehicleVelocity(vehicleid, floatcos(VRotZ, degrees) * VelocityX - floatsin(VRotZ, degrees) * VelocityY, floatsin(VRotZ, degrees) * VelocityX + floatcos(VRotZ, degrees) * VelocityY, VSpeed[2]); return 1; } stock GetVehicleLocalXYVelocity(vehicleid, &Float:VelocityX, &Float:VelocityY) { // FUNCTION: Get the local XY velocity of the specified vehicle (velocity relative to its Z rotation angle). new Float:VSpeed[3], Float:VRotZ; GetVehicleVelocity(vehicleid, VSpeed[0], VSpeed[1], VSpeed[2]); GetVehicleZAngle(vehicleid, VRotZ); // Optimized, thanks to Nero_3D. VelocityX = floatsin(VRotZ, degrees) * VSpeed[1] + floatcos(VRotZ, degrees) * VSpeed[0]; VelocityY = floatcos(VRotZ, degrees) * VSpeed[1] - floatsin(VRotZ, degrees) * VSpeed[0]; return 1; }
Example:
Код:
stock VehicleSpeedboost(vehicleid, Float:BoostSpeed) { // Boost the vehicle forward (local Y velocity) while cancelling it's side speed (local X velocity). // This also maintains the vehicle's original forward speed, which means the vehicle will go faster every time it is used. // Using a negative BoostSpeed will boost the vehicle backward. new Float:VLocalSpeed[2]; GetVehicleLocalXYVelocity(vehicleid, VLocalSpeed[0], VLocalSpeed[1]); SetVehicleLocalXYVelocity(vehicleid, 0.0, VLocalSpeed[1] + BoostSpeed); return 1; }
EDIT2: Functions optimized, thanks to Nero_3D.