GetXYInAngleOfPlayer ?
#1

How do i modify this function to return the position left, right or behind of me?
I'd like something like this:
pawn Код:
GetXYInAngleOfPlayer(playerid, &Float:x, &Float:y, Float:angle, Float:distance)
From:
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));
}
EDIT: I made this, going to try it in a sec.
pawn Код:
stock GetXYInAngleOfPos(Float:xpos, Float:ypos, Float:angle, Float:distance, &Float:x, &Float:y)
{
    x = xpos + (distance * floatsin(-angle, degrees));
    y = ypos + (distance * floatcos(-angle, degrees));
}
Reply
#2

I made this ages ago: http://pastebin.com/1hLSAVJu

Usage is inside.

Examples:

There are two ways to do this. Use the player's angle +/- 90 and then use the y (forward/back) offset, or more simply, use the x (left/right) offset. This example uses the x offset of 1 meter, which should be on the right of the player.

pawn Код:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);

// The variables x, y and z are used to hold the initial player's position,
// and the position after the offset calculation will also be stored in them
// (no need for two sets of variables really)
GetCoordinateOffsets(x, y, z, a, 1, 0, 0, x, y, z);
This function is 2D, and doesn't work for x/y rotation of vehicles/objects, so for example, if a vehicle is driving along a road normally and you get the position on the right of it, it'll be fine, but if the vehicle is upside down, it will still be in the same place relative to the world, not on the other side where it should be. This generally isn't an issue though. The Z offset simply increases or decreases the source Z.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)