Set player facing to a object
#1

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
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)