29.11.2012, 12:13
Hello! I've got a question: How can I get the position of an attached object?
Please help!
Please help!
/*
GetAttachedObjectPos
objectid - the objectid to which the attached object is attached to. (not the attached objectid)
Float:offset_x - the distance between the main object and the attached object in the X direction.
Float:offset_y - the distance between the main object and the attached object in the Y direction.
Float:offset_z - the distance between the main object and the attached object in the Z direction.
Float:x - the variable to store the X coordinate, passed by reference.
Float:y - the variable to store the Y coordinate, passed by reference.
Float:z - the variable to store the Z coordinate, passed by reference.
*/
stock GetAttachedObjectPos(objectid, Float:offset_x, Float:offset_y, Float:offset_z, &Float:x, &Float:y, &Float:z)
{
new Float:object_px,
Float:object_py,
Float:object_pz,
Float:object_rx,
Float:object_ry,
Float:object_rz;
GetObjectPos(objectid, object_px, object_py, object_pz);
GetObjectRot(objectid, object_rx, object_ry, object_rz);
new Float:cos_x = floatcos(object_rx, degrees),
Float:cos_y = floatcos(object_ry, degrees),
Float:cos_z = floatcos(object_rz, degrees),
Float:sin_x = floatsin(object_rx, degrees),
Float:sin_y = floatsin(object_ry, degrees),
Float:sin_z = floatsin(object_rz, degrees);
x = object_px + offset_x * cos_y * cos_z - offset_x * sin_x * sin_y * sin_z - offset_y * cos_x * sin_z + offset_z * sin_y * cos_z + offset_z * sin_x * cos_y * sin_z;
y = object_py + offset_x * cos_y * sin_z + offset_x * sin_x * sin_y * cos_z + offset_y * cos_x * cos_z + offset_z * sin_y * sin_z - offset_z * sin_x * cos_y * cos_z;
z = object_pz - offset_x * cos_x * sin_y + offset_y * sin_x + offset_z * cos_x * cos_y;
}
the objectid to which the attached object is attached to. (not the attached objectid) |
stock GetAttachedObjectPos(vehicleid, Float:offset_x, Float:offset_y, Float:offset_z, &Float:x, &Float:y, &Float:z)
{
new Float:deg;
new Float:s;
new Float:objectangle;
new Float:pos[3];
GetVehicleZAngle(vehicleid, deg);
GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
s = floatsqroot(offset_x * offset_x + offset_y * offset_y);
objectangle = atan(offset_y / offset_x);
deg += 90.0;
deg -= objectangle;
x = pos[0] + s * floatcos(deg, degrees);
y = pos[1] + s * floatsin(deg, degrees);
z = pos[2] + offset_z;
}
new Float:X, Float:Y, Float:Z, Float:oX, Float:oY, Float:oZ;
GetAttachedObjectPos(vehicleid, X, Y, Z, oX, oY, oZ);
SetPlayerPos(playerid, oX, oY, oZ);