ArcHandle bug issue

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)

I have no idea what the problem is but base on the vid , I can tell that it is due to the rounding of the angle

1 Like

Did you try removing the +.5 when rounding so it round down?

the glitch doesn’t seem to appear but the rotation is much more glitchy (basically meaning its grid is now wrong).

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.

1 Like

i will work on it later . I am currently typing all of this on mobile lol :laughing:

2 Likes

Hello ! After looking at some script I wrote, I will give you some sample to hopefully help you in your script

1)How I snap the part
I use a custom function that round the number

function round(number, increment)
	return math.round(number*(1/increment))/(1/increment)
end

number is the degree
increment is the step/snap

2)I detect the handle drag by doing this

RotationHandle.MouseDrag:Connect(function(axis, angle, delta)

end)

3)I rotate the part by writing this in the function above

local RoundedDeg = round(math.deg(angle),Increment)
local new = CFrame.Angles(0,math.rad(RoundedDeg),0)
Object.CFrame = (lastCF * new)

Hope it works! If you have questions or problem, be sure to ask me!

1 Like

The issue still seems to be occuring when the increment is above 23

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.

1 Like

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

1 Like

True, i will cap it out at 45 degrees, thank you for your help, I really appreciate it.

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