Rotate prop on x,y,z axis

Hello all,

So! I’m working on a menu that allows prop manipulation. You spawn in the prop, and then you can rotate and move the prop nearest to you. The spawning part was easy, I’ve done that all but I haven’t been able to figure out the rotation or movement part.

local degrees = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360}
	local position = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360}
	
	-- Rotation --
	local rotation = _menuPool:AddSubMenu(manipulation, "Rotation", "Rotates nearest object")
		local x = NativeUI.CreateSliderItem("X", degrees, 1, "Rotate on the X axis", false)
		local y = NativeUI.CreateSliderItem("Y", degrees, 1, "Rotate on the Y axis", false)
		local z = NativeUI.CreateSliderItem("Z", degrees, 1, "Rotate on the Z axis", false)
		rotation:AddItem(x)
		rotation:AddItem(y)
		rotation:AddItem(z)
	
	rotation.OnSliderChange = function(sender, item, index)
        rotation = item:IndexToItem(index)
		if item == x then
			
		elseif item == y then
			
		elseif item == z then
			
		end
	end

So, if you slide the sliders it will rotate the object on the axis slider you used. Unless anyone has a better idea for achieving this, could someone give me some help as to how to achieve this?

1 Like

Ok, so i’ve figured out rotating the Z axis by changing the header of the entity like so:

local degrees = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360}
	local position = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360}
	
	-- Rotation --
	local rotation = _menuPool:AddSubMenu(manipulation, "Rotation", "Rotates nearest object")
		local x = NativeUI.CreateSliderItem("Pitch", degrees, 1, "Rotate on the X axis", false)
		local y = NativeUI.CreateSliderItem("Roll", degrees, 1, "Rotate on the Y axis", false)
		local z = NativeUI.CreateSliderItem("Yaw", degrees, 1, "Rotate on the Z axis", false)
		rotation:AddItem(x)
		rotation:AddItem(y)
		rotation:AddItem(z)
	
	rotation.OnSliderChange = function(sender, item, index)
        rotation = item:IndexToItem(index)
		if item == x then
			
		elseif item == y then
			
		elseif item == z then
		
			local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), true))
		
			for k,v in pairs(Objects) do 
				for k,v in pairs(v) do 
					local hash = GetHashKey(v.Object)
					local object = GetClosestObjectOfType(x, y, z, 1.0, hash, false, false, false)
					if object ~= 0 then
						SetEntityAsMissionEntity(object)
						--print(GetEntityHeading(object))
						print(item:IndexToItem(index) + .0)
						SetEntityRotation(object, GetEntityPitch(object), GetEntityRoll(object), item:IndexToItem(index) + .0, 2, true)
					end
				end
			end
			
		end
	end

Generally you’ll want to work with quaternion angle manipulations to prevent gimbal lock.