Using ArcHandles to create increment for rotation?

I am using the ArcHandles which returns these named parameters for a function:
axis, relativeAngle, deltaRadius
Axis = axis being rotated (X, Y, Z)
RelativeAngle and DeltaRadius are singular numbers that go from negative to positive. I have no idea how to use them but my guess is that they may be in radians.

I want to create a rotation increment similar to how you can set how many degrees to increment in Studio. Roblox wiki does not provide clear explanation about what these parameters are so I had to take guesses and what not while printing out numbers a lot.

local degreesIncrement = 45 -- degrees
local axisangle = Vector3.FromAxis(axis)
axisangle = axisangle * relativeAngle
part.CFrame = part.CFrame * CFrame.Angles(axisangle.X, axisangle.Y, axisangle.Z)

This is what I have and I tried many ways to do my increment but I could not find a way to do it. For non-rotation handles, I incremented by comparing a delta to the increment value.

In the case you don’t understand increment, its a grid snap but for rotation, for example a rotation increment of 45 degrees means that rotating once will rotate 45 degrees and no less.

Rotation in one axis is really just a singular intvalue just like position in one axis. So the idea and function would be the same.

This is a function I made, which I actually quite often use for personal work and it’s been incredibly useful to me so far:

function SnapToClosestIncrement(num, increment)
	local leftOvers = num % increment
	local roundedNum = math.floor((leftOvers / increment)+.5)
	local divisions = (num - leftOvers) / increment
	divisions = divisions + 1 * roundedNum
	local snapNum = increment * divisions
	
	return snapNum
end

Edit: I wonder why your post was initially made 2 months ago, though… :thinking:

1 Like

Weird, did the post get bumped somehow? Handles and ArcHandles is a quiet subject so I appreciate the answer and will test it out when I get the chance!

Also since you’re using math.floor, it would round to an integer, my increment may be something like 0.6 or 42.55. How would I change that to work in those cases?

Could it be something like changing the roundedNum to this?

local roundedNum = math.floor((leftOvers / increment)+.5)*increment

It should work nonetheless because roundedNum is simply just to get a value between 0 and 1 to decide whether to go one increment up or not from divisions.

Just try it out. Don’t worry about the technical part of it before you have.