AttachElementsOffsets
This article concerns the note left in attachElements.
Explanation
The offset coordinates reflect the object space, not the world space. This means that if you were to calculate coordinate and rotation offsets between "theElement" and "theAttachToElement", they would not always be correct.
The example script below places a plane facing upward on a silo. The positioning was done manually in the map editor and the coordinates were saved to the script. These coordinates are reflected in the initial creation of objects "shuttletable[1]" and "shuttletable[2]".
The problem is we will need the offsets of the "theElement" in relation to "theAttachToElement". "theAttachToElement" becomes 0,0,0,0,0,0 and "theElement" will inherit the exact same coordinates and rotation, unless offsets are specified when using the attachElements function.
Example
Start freeroam resource and paste this into the console:
setpos 1904.7426757813 -2411.1262207031 13.53911781311
Now, use the following script and look at the rocket. See how it is off center? This means the relation to the actual game world coordinate system has changed.
If you change rocketRZ to 0 (the silo object that the plane in attached to), this will put the rocket in the correct position. So what happened? The silo is "theAttachToElement" and it becomes 0,0,0,0,0,0. This example is unusual in that you have essentially fixed your problem. The silo looks the same all the way around. Although it is no longer rotated the application still works. However, you will find that to use the correct rotation of the silo ("theAttachToElement"), you will need a different set of X,Y,Z coordinates.
--This example illustrates the problem with using the world coordinate math to calculate offsets. --Change rocketRZ to 0 to get the correct position. local rocketX = 1925.022705 local rocketY = -2450.944336 local rocketZ = 18.053474 local rocketRX = 0 local rocketRY = 0 local rocketRZ = 69.61437 local vehX = 1925.112793 --more is forward local vehY = -2446.260742 -- less is forward local vehZ = 26.692139 local vehRX = 89.38142 local vehRY = 0.030000 local vehRZ = 177.90356 shuttletable = {} shuttletable[1] = createObject ( 17050, rocketX, rocketY, rocketZ, rocketRX, rocketRY, rocketRZ ) shuttletable[2] = createVehicle ( 519, vehX, vehY, vehZ, vehRX, vehRY, vehRZ ) attachOffsetX = vehX-rocketX attachOffsetY = vehY-rocketY attachOffsetZ = vehZ-rocketZ attachOffsetRX = vehRX-rocketRX attachOffsetRY = vehRY-rocketRY attachOffsetRZ = vehRZ-rocketRZ attachElements( shuttletable[2], shuttletable[1], attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ )