25.04.2013, 17:54
I'm trying to make a thing that makes a player's vehicle face the center of SA (done - easy) and go towards it, with the same speed. I'm about 90% there, but I'm not an expert with velocity etc. and I'm trying to make the velocity the same speed as BEFORE the function was called.
Here's the mess I have so far:
The thing is, now I think about it, I also need the Z velocity to be counted also. For example, if I'm in a Hydra flying STRAIGHT DOWN at 50 mph (example), when I type this command I want to be going towards the center of SA at 50 mph. The main thing I know is that the sum of the three velocities (x/y/z) must be the same BEFORE and AFTER, and the proportions will be different (due to changed angle).
I've tried many things, but haven't gotten very close. Help appreciated :<
Here's the mess I have so far:
pawn Код:
CMD:center(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
// Make the vehicle face the center of SA
new pAngle = SetPlayerLookAt(playerid, 0, 0);
// Set velocity to go toward center of SA
new Float:velX, Float:velY, Float:velZ;
GetVehicleVelocity(vehicleid, velX, velY, velZ);
new Float:vAngle = float(pAngle);
new Float:total_lat_velocity = floatabs(velX) + floatabs(velY);
// We need the same lateral velocity after (so as that the speed is the same).
Debug_SCMFORMAT("Vel: %0.2f (X: %0.2f + Y: %0.2f)", total_lat_velocity, velX, velY);
SetVehicleVelocity(vehicleid, floatsin(-pAngle, degrees) * total_lat_velocity, floatcos(-pAngle, degrees) * total_lat_velocity, velZ);
return 1;
}
I've tried many things, but haven't gotten very close. Help appreciated :<