open.mp forum
[Pawn] Take the angle of a position - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Take the angle of a position (/showthread.php?tid=1713)



Take the angle of a position - Marllun - 2021-02-26

I would like to know how I get the angle of an X, Y,?Z coordinate, To use for example in the function SetPlayerFacingAngle


Example:

stock Float:GetAnglePos(Float:x, Float:y, Float:z) {
?Code..
return angle;
}


RE: Take the angle of a position - Freaksken - 2021-02-26

Do you mean the angle between some point?and the position of the player?


RE: Take the angle of a position - arber - 2021-02-26

I guess you want this

https://open.mp/docs/scripting/functions/GetPlayerFacingAngle


RE: Take the angle of a position - Marllun - 2021-02-26

I want to make the player turn the angle to a specific position.



This function does not exist in the SAMP Native functions, please do not come with GetPlayerFacingAngle, SetCameraBehindPlayer.


RE: Take the angle of a position - Virsenas - 2021-02-26

https://www.burgershot.gg/showthread.php?tid=218&pid=10013#pid10013



You will have to edit the function so you have to enter the x, y and z coordinates instead of playerid (faceplayerid).


RE: Take the angle of a position - Freaksken - 2021-02-27

(2021-02-26, 11:55 PM)Virsenas Wrote: https://www.burgershot.gg/showthread.php?tid=218&pid=10013#pid10013



You will have to edit the function so you have to enter the x, y and z coordinates instead of playerid (faceplayerid).
I know the function was not created by you, but still ...
Wtf, is all this stuff done with floatsub, floatadd and such. None of that is needed as atan2 already takes into account the sign of both arguments in order to determine the quadrant.

This is all that's needed:
PHP Code:
PlayerFacePosition(playeridFloat:xFloat:y)
{
    new 
Float:pxFloat:pyFloat:pz;
    
GetPlayerPos(playeridpxpypz);

    new 
Float:angle atan2(pypx);
    
SetPlayerFacingAngle(playeridangle 90.0); 

The -90.0 is to account for the weird GTA angle orientation. The actual angle between the 2 points is without this subtraction.