How would I smoothly lock the default camera view at a certain heigh/position

I’m making a car garage system and I’m using the default roblox camera view drag (Right mouse button) as like a look around the car sorta thing. The camera subject is also the car, not the player. What I’m tryng to achieve though is a camera height restriction which is basically stopping the camera if you try to drag it to a certain height or postion.

The video above is footage from Tank Warfare on roblox. I can move the camera view around freely, only when I try to move the camera up it has a stopping point where it restricts the camera from going any further. Or when I try to move the camera view down it stops right before it hits the ground. The video shows exactly what im trying to achieve and any help would be greatly appreciated.

So create a part where you want your camera to be.
Then insert a script (local script) and type the following code

local cameraPart = workspace.CameraPart -- the part where you want camera position to be
local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable -- makes camera not movable and makes it scriptable for the developers
camera.CFrame = cameraPart.CFrame -- Sets the camera position (includes height), rotation to the part's position/rotation.

Then you can make your own custom moment system.

Uh, honestly, this is a pretty jank script but uh…
Source: How to clamp the player's camera rotation on one axis?

local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
while game["Run Service"].RenderStepped:Wait() do
	
	local rX, rY, rZ = camera.CFrame:ToOrientation()
	print(math.deg(rX))
	local limX = math.clamp(math.deg(rX), -45, 45)
	
	if limX <= -44 then
		limX = limX + 0.4
	end
	if limX >= 44 then
		limX = limX - 0.4
	end
	camera.CFrame = CFrame.new(camera.CFrame.p) * CFrame.fromOrientation(math.rad(limX), rY, rZ)
end

I’ll explain, what’s going on, the variable limitX is using math.Clamp, which allows you to take numbers and make sure they can’t pass or decrease lower than or higher than you’re preset numbers, aka. -45, 45, so… The variable grabs the degrees of rotationX makes sure it can’t pass/decrease through -45 or 45 and then sets the camera cframe orientation rotationX equal to limitX (Radians), meaning the rotation can’t pass -45 degrees or 45 degrees.

P.S. I’ve tried to minimize the stuttering as much as I could on the edges, I’m too tired rn to find a perfect solution, sorry ;-;

This is good, although I’m trying to make the locking more smooth. What I mean by that is when you reach the locking height the camera view is kind of shaky and it constantly gets pulled back when you try to move it any further. What I’m trying to acheive is making the camera firmly stop when you try to move it any further.

In case you still haven’t solved this, or anyone else has this problem in future, this is how to smoothly clamp vertical camera rotation: