Trying to create a rotate tool, but it's weird right now

Greetings! I am working on a Rotate tool, but it is acting not so smooth:

If you can help me make this smooth like the Roblox Rotate tool, that would be great! I want the increment to follow this attribute:

script.Parent.Parent.Parent.Settings:GetAttribute("RotateIncrement")

Thanks in advance!

local RotateTool: ArcHandles = script.Parent

local MouseDownEvent
local MouseDragEvent

RotateTool:GetPropertyChangedSignal("Adornee"):Connect(function()
	if MouseDragEvent then
		MouseDragEvent:Disconnect()
	end

	if RotateTool.Adornee then
		MouseDragEvent = RotateTool.MouseDrag:Connect(function(Axis, Angle, Radius)
			local RotateIncrement = script.Parent.Parent.Parent.Settings:GetAttribute("RotateIncrement")
			local Increment = math.round(Angle * RotateIncrement)

			if Axis == Enum.Axis.X then
				RotateTool.Adornee.CFrame *= CFrame.Angles(Increment,0,0)
				return
			end
			
			if Axis == Enum.Axis.Y then
				RotateTool.Adornee.CFrame *= CFrame.Angles(0, Increment,0)
				return
			end
			
			if Axis == Enum.Axis.Z then
				RotateTool.Adornee.CFrame *= CFrame.Angles(0,0, Increment)
				return
			end
		end)
	end
end)
math.round(angle * RotateIncrement) / RotateIncrement / 10

this was the only line of code that stood out to me. How come you are multiplying by a number, rounding, then dividing by that number again?

I am unfamiliar with how this works, so if you could provide me with these two things, I can draft you a solution.

Give me an example of what angle returns, and what it means.
What do you have RotateIncrement set to in this example?

Thanks.

I was just trying things out to see if I could fix the issue myself.

ArcHandle.MouseDrag.relativeAngle (A number)
https://developer.roblox.com/en-us/api-reference/event/ArcHandles/MouseDrag

15


Also sorry that ArcHandles is called ScaleTool. This is based off of my scale tool. Should probably use Types next time I make a post like this.

yeah i just finished messing around with arc handles. I HATE RADIANS. I figured it out tho. The MouseDrag event passes the angle value which is the value the player has rotated the handle since they clicked down. The issue is that it fires every time the mouse moves. SO if you think about it YOU are adding the total amount rotated each frame basically. Good news is that this is an easy fix. Think of angle as the total offset rotated by the player since they clicked on the handle. You were using it as if angle was the displacement from the last frame.

local initialCF
rotateTool.MouseButton1Down:Connect(function()
    initialCF = adornee.CFrame

    rotateTool.MouseDrag:Connect(function(axis, angle, radius)
        if axis == Enum.Axis.X then
            adornee.CFrame = initialCF * CFrame.Angles(angle,0,0)
        end
        --and the same for each other axis
    end)
end)

--------Edit--------
Just checked on it and its smooth and works but when you click on it, it will clip to a direction. ill see if i can work on a fix for it.

Hey, I am figuring out how to make it rotate with increments. This is the attribute that I am using for increments
Kind of like Studios:
image

script.Parent.Parent.Parent.Settings:GetAttribute("RotateIncrement") -- I have it 15 at the moment.

Do you know how I can add it to your system?

yes. So as i said earlier the angle parameter is the offset angle that has been rotated. So all you need to do to make it snap like you want is add an extra condition to the if statements. The angle param is in radians so the end result would look something like this.

 local initialCF
rotateTool.MouseButton1Down:Connect(function()
    initialCF = adornee.CFrame

    local lastSnapValue = 0
    local fixedRotVal = 0
    rotateTool.MouseDrag:Connect(function(axis, angle, radius)
        
        if axis == Enum.Axis.X and math.abs(math.deg(angle) - lastSnapValue) > RotateIncrement then
            fixedRotVal = math.rad( math.round( math.deg( angle) / RotateIncrement) * RotateIncrement)

            adornee.CFrame = initialCF * CFrame.Angles(fixedRotVal ,0,0)

            lastSnapValue = fixedRotVal
        end
        --and the same for each other axis
    end)
end)

funnily enough i ended up doing basically the same thing i said was weird in my first comment lol.

--------EDIT--------
If you need me to clarify how anything works just let me know