AttachElementsOffsets: Difference between revisions
m (To be checked...) |
m (→Example) |
||
Line 8: | Line 8: | ||
<syntaxhighlight lang="lua">setpos 1904.7426757813 -2411.1262207031 13.53911781311</syntaxhighlight> | <syntaxhighlight lang="lua">setpos 1904.7426757813 -2411.1262207031 13.53911781311</syntaxhighlight> | ||
Now, use the following script and look at the rocket. See how it is off center? | Now, use the following script and look at the plane on the rocket. See how it is off center? It is off center despite the fact you found the positions in the map editor and calculated the offsets. If you commented out the [[attachElements]] line you will see that the plane is created in the correct position in relation to the rocket in terms of '''world coordinates'''. | ||
In this example, if you make "rocketRZ = 0" you will have the correct coordinates. Again, because the offsets are based off "theAttachToElement". If you kept any rotations in the object, it would change the XYZ coordinates "theElement" would need to be attached at. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> |
Revision as of 04:13, 21 March 2011
This article concerns the note left in attachElements.
Explanation
The offset coordinates reflect the object space, not the world space. This means that you cannot simply visualize the attachment in the map editor and calculate the offsets between the 2 sets of world coordinates between "theElement" and "theAttachToObject".
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 plane on the rocket. See how it is off center? It is off center despite the fact you found the positions in the map editor and calculated the offsets. If you commented out the attachElements line you will see that the plane is created in the correct position in relation to the rocket in terms of world coordinates.
In this example, if you make "rocketRZ = 0" you will have the correct coordinates. Again, because the offsets are based off "theAttachToElement". If you kept any rotations in the object, it would change the XYZ coordinates "theElement" would need to be attached at.
--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 )