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)
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.
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