Is player facing to 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: Is player facing to object (
/showthread.php?tid=517551)
Is player facing to object -
audriuxxx - 05.06.2014
Hi,
How to check is player facing to specife object?
AW: Is player facing to object -
Nero_3D - 05.06.2014
Calculate the angle between the two positions (player pos and object pos) and compare it with the facing angle of the player
Well that is that I just wrote, no clue if that works flawless but give it a try
pawn Код:
IsPlayerFacingPos(playerid, Float: degrees, Float: X, Float: Y) {
new
Float: pX,
Float: pY,
Float: pZ
;
if(GetPlayerPos(playerid, pX, pY, pZ)) {
pX = -atan2(pX - X, pY - Y);
if(pX < 0.0) {
pX += 360.0;
}
GetPlayerFacingAngle(playerid, pY);
pX -= pY;
if(pX < -180) {
pX += 360.0;
}
else if(pX > 180.0) {
pX -= 360.0;
}
return (-degrees < pX < degrees);
}
return false;
}