20.04.2012, 15:56
This may help:
However that works on angles, if you want to know if they are in the player's line of sight, you will have to use some maths with GetPlayerCameraPos and GetPlayerCameraFrontVector..
pawn Код:
stock SetPlayerFacePlayer(playerid, faceplayerid)
{
new Float:Px, Float:Py, Float: Pa;
GetPlayerPos(playerid, Px, Py, Pa);
new Float:fpX, Float:fpY, Float: fpZ;
GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
Pa = floatsub(Pa, 90.0);
if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}