DragFrame orientation having issue with reading CFrame value

I’m trying out the new DragDetectors but have run into a problem reading the DragFrame Orientation X value.

I want to use a lever (NOT a slider Position like all the tutorial places or documentation suggest) but because of my very basic knowledge of CFrames I can’t get the Orientation.X value to print. I know how to convert radians to degrees so that’s not the issue.

When I playtest and look at the DragFrame.Orientation.X value it changes with the lever from 0 to 90 as I move it. Simple, right?
I want to use just the X value in the formula to change the chandelier lights Brightness in the folder. Anything I read seems to indicate I have to get the CFrame of the Lever Part and use that, but since its CFrame is rotated in the workspace the X,Y,Z values don’t just change from 0 to 90 as I’d like.

lights = script.Parent.Lights

drag = script.Parent.Lever.DragDetector

--[[     --issues here I can fix, but I need to use the degrees of the X angle.
function dimmer(angle)
	for _, light in next, lights:GetChildren() do
		light.Transparency = angle/180 + .5
		if light.Name == "Bulb" then
			light.Light.Brightness = angle/180
		end
	end
end]]

function leverChanged()
	local angle = drag.DragFrame.Rotation
	--dimmer(angle) 
	print("lever angle = ", angle)
end

drag:GetPropertyChangedSignal("DragFrame"):Connect(leverChanged)

The prints I get in the output window look like CFrame values to me:
01:06:37.826 lever angle = 0, 0, 0, 1, -3.45619228e-05, 5.9604627e-08, 1.5050171e-05, 0.433901489, -0.900960326, 3.1113057e-05, 0.900960326, 0.433901489 - Server - DimmerScript:18

I know it’s probably such a simple thing to fix, but man I always have problems converting CFrame values to something I can use in my scripts…
Thanks!

1 Like

You can use CFrame:ToOrientation() to get a Tuple of 3 numbers (representing X, Y, and Z values respectively).

local rX, rY, rZ = drag.DragFrame:ToOrientation()
print(rX) -- if DragFrame's X rotational axis is equivalent to math.rad(90), rX should also return a close enough 90 degrees with negligible error, like 90.00000250447816

Sweet, thanks. I’ll give that a try tonight.
As you can see witht the script I’m trying to change Brightness with a formula according to the angle. Even a 2° variation wouldn’t hurt it one bit.

Thanks so much.
Seems to me this should’ve been put as a simple value you could pick up in a script like a HingeConstraint CurrentAngle since it’s a value directly driven by the Orientation of the lever to the ReferenceInstance Part. It even displays the angle in degrees.
Something easy to read, like local angle = drag.DragFrame.Orientation.X

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.