Issue with custom camera controller rotation [Unsolved]

Hello all!

I’m currently working on a custom camera controller. The camera’s rotation can be set by right-clicking and dragging, but when the player lets go it lerps back to the character’s orientation.


Let’s say the character’s orientation is at 20 degrees, but the camera is at 290 degrees. I need to make the lerp go from 290-> 0 → 20 in order to make it smooth.

I’ve tried doing this, but because of the easing of lerping it is not smooth.


I’ve tried many things to get this to properly work, but I can’t seem to get it working properly.

Here is my code:

Any insight is appriciated, I’ve messed with this for about an hour now and its driving me crazy. :sweat_smile:

-- Rotate Camera --
if isHoldingRightClick then
	local delta = UIS:GetMouseDelta()
	local rotate = delta.X * cameraSensitivity

	angle += rotate 

	local orient = root.Orientation.Y

	if orient < 0 then
		orient += 360

	local distance = math.abs((angle + 180) - orient)

	--if distance > 180 then
	--	???
	--	angle = IntegerLerp(angle, orient, 0.1)



This is a totally custom controller so I used the Scriptable type.

Still at a loss on how this would be done. I’d say the main thing I need a good way to consistently find the distance no matter the rotation between two points on a circle.

What would be a good formula for doing this on a 360 degree circle where two points can be anywhere on its circumference? I just need to know how many degrees the shortest distance is, no matter where the points are.

This formula didn’t work when I began to rotate my character. I’m assuming this is due to 0 degrees always being in the same direction.

local distance = (angle - orient)

Plus, if orient is 20deg and angle is 350deg its a problem. Even though the distance is only 30 degrees.

Thanks in advance.