Maths (Velocity) - 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: Maths (Velocity) (
/showthread.php?tid=433063)
Maths (Velocity) -
MP2 - 25.04.2013
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:
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;
}
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 :<
Re: Maths (Velocity) -
Sithis - 25.04.2013
You will basically have to transform the velocity axis and turn them around in the new direction like a cube, and apply the new velocity like you're already doing. I'll try and think for you and draw some calculations later on
Re: Maths (Velocity) -
MP2 - 25.04.2013
That doesn't really help me. I'm clueless.
Re: Maths (Velocity) -
Pottus - 25.04.2013
I'm not really sure how to do this but I would recommend sending a PM to Stylock aka (YJIET) he helped me with some object rotation code recently and has a very strong affinity for these sort of mathematical problems I'm almost certain he could provide a solution for you.
Re: Maths (Velocity) -
MP2 - 25.04.2013
Actualy, I've altered it a little bit to include the Z velocity and it appears to work now. It SLIGHTLY increases the player's speed, but that's kinda what I wanted anyway.
Re: Maths (Velocity) -
Sithis - 25.04.2013
Quote:
Originally Posted by MP2
Actualy, I've altered it a little bit to include the Z velocity and it appears to work now. It SLIGHTLY increases the player's speed, but that's kinda what I wanted anyway.
|
Great. It's what i wanted to suggest anyway. Good luck with the script!