Basically my code works as intended but when the increment is bigger than 23 the rotation starts becoming glitchy displayed in this video: Devforum support (youtube.com)
Here is my code:
local ArcHandle = script.Parent:WaitForChild("ArcHandles")
local Object = ArcHandle.Adornee
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Increment = 25
local LastCF = nil
local function round_number(number)
return math.floor((number / Increment) + .5) * Increment
end
ArcHandle.MouseDrag:Connect(function(axis, relativeangle)
warn(axis, relativeangle)
if axis == Enum.Axis.Y then
--local newAngle = round_number(math.deg(relativeangle))
Object.CFrame = LastCF * CFrame.Angles(0,math.rad(round_number(math.deg(relativeangle))),0)
end
--LastCF = Object.CFrame
end)
ArcHandle.MouseButton1Down:Connect(function()
LastCF = Object.CFrame
end)
Removing the + .5 has helped stop the glitch but the incrementation is now glitchy meaning its start point is different when rotating to its start point.
local ArcHandle = script.Parent:WaitForChild("ArcHandles")
local Object = ArcHandle.Adornee
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Increment = math.rad(45)
local LastCF = nil
local function round_number(number)
local modulus = number % Increment
local divisions = (number - modulus) / Increment
divisions = divisions + 1 * math.floor((modulus / Increment)+.5)
return divisions * Increment
end
ArcHandle.MouseDrag:Connect(function(axis, relativeangle)
warn(string.sub(math.deg(relativeangle),0,3), math.deg(round_number(relativeangle)))
if axis == Enum.Axis.Y then
Object.CFrame = LastCF * CFrame.Angles(0,round_number(relativeangle),0)
end
end)
ArcHandle.MouseButton1Down:Connect(function()
LastCF = Object.CFrame
end)
Changed the rounding function. (also changed increment itself to be in radians.) Tested it in studio, it works like a charm. If it’s still causing issues its something else interfering with the CFrame.
the increment is able to go above 23 but when it goes above 135 it seems to be causing the same issue, its definitely better than the code i had before so thank you for the improvement but is there a fix for it glitching when it gets above 135?
the issue seems to be connected to the real-time rotation of the part itself, because all issues disappear when the part CFrame is not updated.
Lazy fixes i can think of right now are having a cap on the increment at 45 because that’s what every normal person would use at max or using a duplicate model for whenever drag starts at increment above 45. (create new clone of part. Rotate that part visually then update the real part when drag is released.) or update the part only when drag is released