AttachElementsOffsets: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "'''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 wer...")
 
mNo edit summary
Line 1: Line 1:
'''This article concerns the note left in [[attachElements]].'''
'''This article concerns the note left in [[attachElements]].'''


==Explanation==
==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 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".
 
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==
==Example==
Line 12: Line 9:
<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? This means the relation to the actual game world coordinate system has changed.
Now, use the following script and look at the rocket. See how it is off center? Despite the fact you found the positions in the map editor and calculated the offsets. If you commented out [[attachElements]] you will see that it is in the correct position in terms of world coordinates.  


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.
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:08, 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 rocket. See how it is off center? Despite the fact you found the positions in the map editor and calculated the offsets. If you commented out attachElements you will see that it is in the correct position in terms of world coordinates.

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 )