SA-MP Forums Archive
mathematic-informtic - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: mathematic-informtic (/showthread.php?tid=266806)



mathematic-informtic - Roko_foko - 06.07.2011

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.


Re: mathematic-informtic - Jochemd - 06.07.2011

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


Re: mathematic-informtic - RyDeR` - 06.07.2011

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;
}



Re: mathematic-informtic - Roko_foko - 07.07.2011

Thank you


Re: mathematic-informtic - Roko_foko - 07.07.2011

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?


AW: Re: mathematic-informtic - Nero_3D - 07.07.2011

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