Checking if player is facing an object
#1

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

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

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

Facing a object by 'player angle' or 'camera' ?
Reply
#5

Player angle.
Reply
#6

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

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

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

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

BUMP
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)