A help related with GetXYInFrontOfPlayer.
#1

Hello, I saw the GetXYInFrontOfPlayer function. I want to check the direction of X and Y, for that I need (I guess) the angle at which the X and Y will be in front of the player? Is there a way to check the angle at which the xy will be in front of the player. Thank you.

pawn Код:
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));
}
Reply
#2

It think this already does that...what exactly do you want with it ? check if a player is in front of you ?

Maybe you want something like this;

pawn Код:
stock GetXYSetAngle(playerid, &Float:x, &Float:y, Float:distance,Float:angle)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    a += angle;
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

this checks the xy angle in front of you and the distance in that angle to be checked
Reply
#3

Quote:
Originally Posted by AIped
Посмотреть сообщение
It think this already does that...what exactly do you want with it ? check if a player is in front of you ?

Maybe you want something like this;

pawn Код:
stock GetXYSetAngle(playerid, &Float:x, &Float:y, Float:distance,Float:angle)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    a += angle;
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

this checks the xy angle in front of you and the distance in that angle to be checked
I want to get the angle at which the player will be facing XY.



I want this code to return 120 (for the above case) by using the XY of the red object.
Reply
#4

Try this perhaps:
pawn Код:
new Float:x, Float: y, Float:z, Float:fa;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, fa);

// Calculate position to left of player
x = (x + 0.75 * floatsin(-fa + -90,degrees));
y = (y + 0.75 * floatcos(-fa + -90,degrees));

// Calculate create offset
x = (x + 1.0 * floatsin(-fa,degrees));
y = (y + 1.0 * floatcos(-fa,degrees));
Reply
#5

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
Try this perhaps:
pawn Код:
new Float:x, Float: y, Float:z, Float:fa;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, fa);

// Calculate position to left of player
x = (x + 0.75 * floatsin(-fa + -90,degrees));
y = (y + 0.75 * floatcos(-fa + -90,degrees));

// Calculate create offset
x = (x + 1.0 * floatsin(-fa,degrees));
y = (y + 1.0 * floatcos(-fa,degrees));
pawn Код:
stock GetXYSetAngle(playerid)
{
    new Float:x, Float: y, Float:z, Float:fa;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, fa);

    // Calculate position to left of player
    x = (x + 0.75 * floatsin(-fa + -90,degrees));
    y = (y + 0.75 * floatcos(-fa + -90,degrees));

    // Calculate create offset
    x = (x + 1.0 * floatsin(-fa,degrees));
    y = (y + 1.0 * floatcos(-fa,degrees));
}
Will it work for all the angles? And how to use it? if(GetXYSetAngle(playerid) == 120) ?
Reply
#6

Quote:
Originally Posted by De4dpOol
Посмотреть сообщение
pawn Код:
stock GetXYSetAngle(playerid)
{
    new Float:x, Float: y, Float:z, Float:fa;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, fa);

    // Calculate position to left of player
    x = (x + 0.75 * floatsin(-fa + -90,degrees));
    y = (y + 0.75 * floatcos(-fa + -90,degrees));

    // Calculate create offset
    x = (x + 1.0 * floatsin(-fa,degrees));
    y = (y + 1.0 * floatcos(-fa,degrees));
}
Will it work for all the angles? And how to use it? if(GetXYSetAngle(playerid) == 120) ?
Its a long time ago i used that function. i see now that i didnt explane it correctly earlyer.
hold on im trying to refresh my memory XD
Try GetXYSetAngle(playerid,5.0,120);
Reply
#7

I made a new one ..explained a bit in the function hope it works;

pawn Код:
stock GetXYDeadpOol(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);
    }
    a +=120;//  <---you can just change the angle here. Its set to 120 like you want now.
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
Here is an example of another function with the above function in it.

pawn Код:
stock IsPlayerLeftofPlayer(playerid,targetid,Float:distance,Float:range)
{
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid))return 0;
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(targetid, x, y, z);//my pos
        GetXYDeadpOol(targetid,x,y,distance);
        if(IsPlayerInRangeOfPoint(playerid,range,x,y,z))return 1;
    }
    return 0;
}
Note: 180 is exact left of the player...not 120..but you want 120 so thats okay i guess
Reply
#8

Quote:
Originally Posted by AIped
Посмотреть сообщение
Its a long time ago i used that function. i see now that i didnt explane it correctly earlyer.
hold on im trying to refresh my memory XD
Try GetXYSetAngle(playerid,5.0,120);
GetXYSetAngle(playerid,5.0,120) But I don't have the angle 120 I need to find it. I need a function kind of opposite to GetXYInFrontOfPlayer in which you have angle and you get XY in front, I have the XY and need to get the angle.

EDIT: testing the new code you posted.
EDIT 2: Hold! will it do what I want? to find the angle?
Reply
#9

You just want to get the angle between two points than use that
pawn Код:
stock Float: GetAngle(Float: X1, Float: Y1, Float: X2, Float: Y2) // player - target
    return -atan2(X2 - X1, Y2 - Y1); // returns values between (180.0) and (-180.0)
Reply
#10

lol pm me with you skype i'll explain

Edit: to your Edit2:


yes it should...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)