2021-02-26, 11:53 PM
SetPlayerFacePlayer function. Function was not created by me. I think it was created by a mad german scientist whose name I can't remember.
Code:
SetPlayerFacePlayer(playerid, faceplayerid)
{
? ? new Float:x1, Float:y1, Float: a1;
? ? GetPlayerPos(playerid, x1, y1, a1);
? ? new Float:fpX, Float:fpY, Float: fpZ;
? ? GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
? ? a1 = floatabs(atan((fpY-y1)/(fpX-x1)));
? ? if(fpX <= x1 && fpY >= y1) a1 = floatsub(180, a1);
? ? else if(fpX < x1 && fpY < y1) a1 = floatadd(a1, 180);
? ? else if(fpX >= x1 && fpY <= y1) a1 = floatsub(360.0, a1);
? ? a1 = floatsub(a1, 90.0);
? ? if(a1 >= 360.0) a1 = floatsub(a1, 360.0);
? ? if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, a1);
? ? else SetVehicleZAngle(GetPlayerVehicleID(playerid), a1);
}