# Custom attachElements

## Recommended Posts

Hi,

I'm writing custom function attachElementsEx (alternative for attachElements https://wiki.multitheftauto.com/wiki/AttachElements).

```function attachElementsEx( theElement, theAttachToElement, ox, oy, oz, orx, ory, orz )
...  -- here I saving offsets etc.
end

function()
...  -- here I calculating and updating positions and rotations of attached elements
end
)
```

While I'm calculating end point XYZ (including rotation), I have the following variables:

```local px,py,pz = getElementPosition( theElement )  -- position XYZ of source element
local rx,ry,rz = getElementPosition( theElement )  -- rotation XYZ of source element
local ox,oy,oz  -- position offsets
local orx,ory,orz  -- rotation offsets
```

From this data i have to calculate end position (and rotation) of attached element, but i don't know how to do it. I know how to make same script in 2D dimension, but 3D it's too hard for me.

THX for help

```getElementMatrix
setElementMatrix
```

I don't understand matrices and i don't know how to use it correctly

Matrix is probably the most intuitive representation of element's position and rotation. matrix[1] (X) vector points to the right from the element. matrix[2] (Y) points to the front. matrix[3] (Z) points up. matrix[4] is the position of the element. The first example in the getElementMatrix page may help you to understand how it works.

Thanks, it works! Now i have this what i needed

## Create an account

Register a new account