12.12.2013, 13:40
Hello,
I'm looking for script works as follows:
There are 2 objects.
A using coordinates and angles of these objects are calculated offsets for their mutual attach (AttachObjectToObject)
I have one object and I want to attach to it a second object, so I want to calculate offsets, depending on how they are built objects in space.
This is calculate bad off-sets.
I'm looking for script works as follows:
There are 2 objects.
A using coordinates and angles of these objects are calculated offsets for their mutual attach (AttachObjectToObject)
I have one object and I want to attach to it a second object, so I want to calculate offsets, depending on how they are built objects in space.
Код:
stock AttachAObjectToAObject(objectid,attachtoid,type)
{
if(IsValidObject(objectid) && IsValidObject(attachtoid))
{
new Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz;
new Float:x2,Float:y2,Float:z2,Float:rx2,Float:ry2,Float:rz2;
GetObjectPos(attachtoid,x,y,z);
GetObjectRot(attachtoid,rx,ry,rz);
GetObjectPos(objectid,x2,y2,z2);
GetObjectRot(objectid,rx2,ry2,rz2);
new Float:xy = GetDistanceBetweenPoints(x,y,0,x2,y2,0);
new Float:yz = GetDistanceBetweenPoints(0,y,z,0,y2,z2);
new Float:xz = GetDistanceBetweenPoints(x,0,z,x2,0,z2);
new Float:x3 = x + (xy * floatsin(-rz,degrees)) + (xz * floatcos(-ry,degrees));
new Float:y3 = y + (xy * floatcos(-rz,degrees)) + (yz * floatsin(-rx,degrees));
new Float:z3 = z + (yz * floatcos(-rx,degrees)) + (xz * floatsin(-ry,degrees));
AttachObjectToObject(objectid,attachtoid,x3-x,y3-y,z3-z,rx2-rx,ry2-ry,rz2-rz,type);//bad offsets
return 1;
}
return 0;
}

