Jump to content

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

addEventHandler("onClientPreRender", root, 	
	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:

R8GxQlh.png

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

VQtDGAD.png

Please help me out with the calculations!

Link to comment

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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...