# Problem with effect rotations

## Recommended Posts

Hello!

I am asking for your help in rotation calculations, I am struggling to get done what I want.

I made a script to attach effects to vehicles, but I noticed a problem with some specific effects (for example the one called "petrolcan", which is the effect you get when your character is peeing). I attached this effect to the position of the wheel_rb_dummy and wheel_lb_dummy, now the problem is that when my vehicle turns the effects do not keep their offset rotations, they turn in wrong directions.

Here's my current calculations:

```vehicleEffectData = {
["smoke"] = {
["wheel_lb_dummy"] = {
["petrolcan"] = {x = -0.1, y = 0.3, z = 0.3, rx = -270, ry = 0, density = 1},
},
["wheel_rb_dummy"] = {
["petrolcan"] = {x = 0.1, y = 0.3, z = 0.3, rx = 270, ry = 0, density = 1},
},
},
}

local attachedEffects = {}
local vehicleEffects = {}

function attachEffect(effect, element, pos, rot)
attachedEffects[effect] = { effect = effect, element = element, pos = pos, rot = rot }
addEventHandler("onClientElementDestroy", effect, function() attachedEffects[effect] = nil end)
addEventHandler("onClientElementDestroy", element, function() attachedEffects[effect] = nil end)
return true
end

function()
for fx, info in pairs(attachedEffects) do
local rx, ry, rz = info.rot.x, info.rot.y, info.rot.z
local elementRX, elementRY, elementRZ = getElementRotation(info.element)
local x, y, z = getPositionFromElementOffset(info.element, info.pos.x, info.pos.y, info.pos.z)
setElementPosition(fx, x, y, z)
setElementRotation(fx, rx-(elementRX+90)-180, elementRY-ry+90, elementRZ-rz)
end
end
)

-- inside script:
attachEffect(vehicleEffects[vehicle][effect][partName][effectName], vehicle, Vector3(partX+effectData.x, partY+effectData.y/(seatToEngineDifference*2), partZ+effectData.z), Vector3(effectData.rx or 0, effectData.ry or 0, effectData.rz or 0))```

Images of the current version:

This is the rotation I want to always achieve when I set the rotation inside the table, but this only happens when I am facing this or -(this) direction:

When I face north (the effects rotate as well and they turn inside):

I just noticed I didn't even use the given rotations at this line;

`setElementRotation(fx, rx-(elementRX+90)-180, elementRY-ry+90, elementRZ-rz) -- what do i actually write here?`

but I changed up the variables so many times, nothing seemed to work, probably I copied the wrong version of the script while I was trying to achieve what I wanted.