Oh right, tz should have been z, just corrected it.
What this does is in short rotating the coordinate system. I might sound a bit complicated, but just because I suck at explaining things, basically it is very simple
To explain it, imagine the vehicle is facing exactly north with 0.0° rotation, and its position is stored in x/y/z. If you now increase x (x+1/y/z), youll get a point that is on the right side of the car, near its right door, of course. Reducing it (x-1/y/z) will return a point to its left side. The same about changing y, if you increase it a bit youll get coordinates near the vehicles hood.
Now imagine the vehicle turns by 180°, so its trunk faces to north and the hood to south. If you now increase x youll get a point near the vehicles left side of course, and not the right side. If you just rotate the vehicle by 90° increasing x will even point to the hood of the car. (you already got that in your first post, but maybe this helps others to get the situation)
Using that code, to get a point near the right side of the vehicle you dont just increase x, but you increase the x offset (xoff). E.g. xoff=1 means "give me the position that is 1m to the right side of the vehicle", or yoff=-1 always gives the point that is 1m behind the vehicle, no matter what direction it faces.
zoff is quite useless here, as it just increases the z coordinate, which isnt affected by the rotation of the vehicle anyways.
I made a ready-to-use function from the code, that can be used like GetVehiclePos, but you can specify the offsets i described before.
pawn Код:
stock GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff=0.0, Float:yoff=0.0, Float:zoff=0.0)
{
new Float:rot;
GetVehicleZAngle(targetid, rot);
rot = 360 - rot; // Making the vehicle rotation compatible with pawns sin/cos
GetVehiclePos(vehicleid, x, y, z);
x = floatsin(rot,degrees) * yoff + floatcos(rot,degrees) * xoff + x;
y = floatcos(rot,degrees) * yoff - floatsin(rot,degrees) * xoff + y;
z = zoff + z;
/*
where xoff/yoff/zoff are the offsets relative to the vehicle
x/y/z then are the coordinates of the point with the given offset to the vehicle
xoff = 1.0 would e.g. point to the right side of the vehicle, -1.0 to the left, etc.
*/
}
//Examples:
GetVehicleRelativePos(vehicleid, x, y, z, 1.0, 1.0, 0.0);
// xoff = 1 -> go 1m to the right side of the vehicle
// yoff = 1 -> go 1m to the front of the vehicle
// so this would return about the coordinates of the the front right tire of the car
GetVehicleRelativePos(vehicleid, x, y, z, 0.0, -3.0, 0.0);
// xoff = 0 -> no change, stay between the driver and passenger seat
// yoff = -3.0 -> go 3m back to the vehicle
// so this would return the coordinates near the trunk of the vehicle
So this is a mighty function once you got how it works, as you can get all these coordinates no matter where the vehicle faces.
(Ouch, long text)