mathematic-informtic
#1

Hey,
What is the pawno command for arc tangent(tan or tg on calcualtors). I need to get the angle while I have both of cathetus.
Thanks in advance.
Ps: I need this to SetPlayerFacingAngle to face some near vehicle.
Reply
#2

Atan if I am right, maybe atan2 if you got the positions only.
Reply
#3

Yes, it's "atan" or "atan2" to make it easier.
pawn Код:
stock SetPlayerFacingAngleToPoint(playerid, const Float: dest_X, const Float: dest_Y)
{
    new
        Float: p_X,
        Float: p_Y,
        Float: p_Angle
    ;
    if(GetPlayerPos(playerid, p_X, p_Y, p_Angle))
    {
        p_Angle = atan2((dest_Y - p_Y), (dest_X - p_X)) + 270.0;
        return SetPlayerFacingAngle(playerid, (p_Angle + 180.0));
    }
    return 0;
}
Reply
#4

Thank you
Reply
#5

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Yes, it's "atan" or "atan2" to make it easier.
pawn Код:
stock SetPlayerFacingAngleToPoint(playerid, const Float: dest_X, const Float: dest_Y)
{
    new
        Float: p_X,
        Float: p_Y,
        Float: p_Angle
    ;
    if(GetPlayerPos(playerid, p_X, p_Y, p_Angle))
    {
        p_Angle = atan2((dest_Y - p_Y), (dest_X - p_X)) + 270.0;
        return SetPlayerFacingAngle(playerid, (p_Angle + 180.0));
    }
    return 0;
}
Is there any difference if I don't put "const Float: dest_X" in function parameters, but " Float: dest_X"(without const). If yes, what actually this "const" does?
Reply
#6

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
Is there any difference if I don't put "const Float: dest_X" in function parameters, but " Float: dest_X"(without const). If yes, what actually this "const" does?
It marks the variable as constant, the script can use constant variables more effective

If there is a const before the variable you cant change it within the function

And yes you can put normal variables in there to
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)