SA-MP Forums Archive
Checking if player is facing an 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: Checking if player is facing an object (/showthread.php?tid=363334)



Checking if player is facing an object - JaKe Elite - 27.07.2012

Hi,
I want to know how to check if player is facing an object.


Re: Checking if player is facing an object - Misiur - 27.07.2012

Quite complex situation. You have to get relative position of player and object, then using trigonometry and compare required angle with GetPlayerFacingAngle (warning, 2d only, so it'll work for objects above player).

Other solution will require https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector


Re: Checking if player is facing an object - JaKe Elite - 27.07.2012

Thank you.
Now i have another question.
How to detect the object id of players facing in.


Re: Checking if player is facing an object - Kar - 27.07.2012

Facing a object by 'player angle' or 'camera' ?


Re: Checking if player is facing an object - JaKe Elite - 27.07.2012

Player angle.


Re: Checking if player is facing an object - AIped - 27.07.2012

maybe you can just use

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
mix it with isplayerinrangeofpoint and make sure that the x and y coordinates are the coordinates of the object, then it should check if the object is in front of you i think


Re: Checking if player is facing an object - JaKe Elite - 27.07.2012

No, i was making Remove Building system.
here is my plan, i want to make auto detect object checking
if there is no object surronded then it will not check.


Re: Checking if player is facing an object - Mauzen - 27.07.2012

Loop through all objects and check for each one if the player is facing it would be the most simple way.


Re: Checking if player is facing an object - JaKe Elite - 27.07.2012

Sorry for being n00b is this correct?
I'm using Incognito's Streamer for some custom maps.

pawn Код:
for(new i = 0; i < CountDynamicObjects(); i++)
However i want to remove also the GTA SA Objects.


Re: Checking if player is facing an object - JaKe Elite - 27.07.2012

BUMP