How can I limit the player's camera rotation in a smooth way?

Hello!
I’ve been looking for a method to be able to limit the player’s rotation angle, or just allow it to rotate on a single axis.
The code’s I am using right now:

	RunService.Heartbeat:Connect(function()
		local rX = Camera.CFrame:ToOrientation()	
		local Val = math.clamp(math.deg(rX), -30, 30)
		Camera.CFrame = CFrame.new(Camera.CFrame.p) * CFrame.fromOrientation(math.rad(Val), math.rad(170), 0)	
	end)

This script works well. It limits the Camera to only move on a limited angle on the X axis, and limits it from moving on the Y axis.
But, it’s not smooth at all. It keeps lagging and letting the camera off the limits every time.
Is there a built-in option in one of the camera scripts that allowed me to change the camera rotating limits?

1 Like

Dont use Heartbeat, use Renderstepped

2 Likes

Almost the same results, still not smooth at all.

2 Likes

I’m curious for a solution. Has anyone found one?

Seems there’s no better solution. It’s just Roblox limits, couldn’t find any property which allows doing that.

I think I might have an idea:

What if you just grab the original camera’s angle (CFrame), then use some kind of funny cframe from orientation stuff to get the orientation, and limit the camera based on that?

That’s just what my script was based about, and it works, yet couldn’t manage to smoothen it up perfectly.

Hm. Perhaps using some kind of weird threshold equation, you can achieve that? I believe I have the equation but I’m too busy as of now