In need of one stock function.
#7

pawn Код:
stock SetPlayerLookAt(playerid, Float:x, Float:y)
{
    new Float:Px, Float:Py, Float: Pa;
    if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid), Px, Py, Pa);
    else GetPlayerPos(playerid, Px, Py, Pa);
    Pa = floatabs(atan((y-Py)/(x-Px)));
    if(x <= Px && y >= Py) Pa = floatsub(180, Pa);
    else if(x < Px && y < Py) Pa = floatadd(Pa, 180);
    else if(x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
    else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}
I did not write this function. It looks very messy and there's probably a much better way to write it - but it works.

If you don't want the function to actually set the players' angle, you could just make it return 'Pa' instead (and remember to add a Float: tag to the function).
Reply


Messages In This Thread
In need of one stock function. - by kristo - 25.05.2013, 11:25
Re: In need of one stock function. - by kristo - 26.05.2013, 10:01
AW: In need of one stock function. - by Blackazur - 26.05.2013, 10:06
Re: In need of one stock function. - by kristo - 26.05.2013, 14:53
Re: In need of one stock function. - by Pottus - 26.05.2013, 15:50
Re: In need of one stock function. - by kristo - 27.05.2013, 13:40
Re: In need of one stock function. - by MP2 - 27.05.2013, 14:11
Re: In need of one stock function. - by kristo - 27.05.2013, 14:17

Forum Jump:


Users browsing this thread: 2 Guest(s)