Maths (Velocity)
#1

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 :<
Reply
#2

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
Reply
#3

That doesn't really help me. I'm clueless.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)