SA-MP Forums Archive
Set player facing to a object - 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: Set player facing to a object (/showthread.php?tid=662001)



Set player facing to a object - 3417512908 - 21.12.2018

So I want to set a player to facing to a object,but not change the angle of object.
Please,I am a math noob


Re: Set player facing to a object - Tickle - 21.12.2018

Quote:

stock SetPlayerFacingObject(playerid, object)
{
new Float:Px, Float:Py, Float: Pa;
new Float,Float:y,Float:z;
GetDynamicObjectPos(object, x, y, z);
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);
return SetPlayerFacingAngle(playerid, Pa);
}

Here you go.