SA-MP Forums Archive
SetPlayerVelocity - 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: SetPlayerVelocity (/showthread.php?tid=315875)



SetPlayerVelocity - Universal - 04.02.2012

Hi, the question is how should I use this function to charge player towards his facing direction?
I've tried it myself, but it requires some advanced math and stuff, so I couldnt make it.

Really looking forward!
+ Rep if you'll help me.


Re: SetPlayerVelocity - [XST]O_x - 04.02.2012

pawn Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance) //An important function
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

#define VELOCITY 3.2 //The velocity you want to add

new Float:p_Vel[3];
GetVehicleVelocity(GetPlayerVehicleID(playerid),p_Vel[0],p_Vel[1],p_Vel[2]);
GetXYInfrontOfPlayer(playerid,p_Vel[0],p_Vel[1],VELOCITY);
SetVehicleVelocity(GetPlayerVehicleID(playerid,p_Vel[0],p_Vel[1],p_Vel[2]);
No idea if it'll work...


Re: SetPlayerVelocity - Universal - 04.02.2012

Fixed the problem. Thanks for help, but that didnt helped. All I needed was to do this:
pawn Код:
X = X2 - X;
Y = Y2 - Y;