How do I smoothly rotate camera exceeding clamp angle limit back within the allowed perimeter

Godot Version

Godot Engine v4.7

Question

I’m new to Godot and have made my FPS camera have different rotation perimeters (can’t look straight down unless crouching and no limitations when airborne). My code works in that regard, but whenever the camera’s rotation is greater/lesser than the clamp angle limit (which happens when the character either lands on the ground looking between x >90 ° and <-90°, or un-crouches looking at x < -70°) the camera will snap to the limit whenever I move my camera. I’d like the camera to smoothly rotate back within the clamp boundaries without snapping or player input.


 func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # Mouse lock
func _unhandled_input(event): # Camera rotation stfuf
	if event is InputEventMouseMotion:
		if is_on_floor(): # Camera sensitivity (Ground)
			Head.rotate_y(-event.relative.x * MouseSensitivity) 
		else:  # Camera sensitivity (Airborne)
			Head.rotate_y(-event.relative.x * MouseSensitivity * 0.8)
		Camera.rotate_x(-event.relative.y * MouseSensitivity)
		if is_on_floor() and Crouch == true: # Crouch Perimeter
			Camera.rotation.x = clamp(Camera.rotation.x, deg_to_rad(-90), deg_to_rad(90))
		elif is_on_floor() and Crouch == false: # Standing Perimeter
			Camera.rotation.x = clamp(Camera.rotation.x, deg_to_rad(-70), deg_to_rad(90))

You can separate the “actual rotation” of the camera from the “target rotation” of the camera. Then you can use a Tween or Interpolation to have the “actual rotation” always smoothly follow the “target rotation”.
With this, even when you clamp the “target rotation”, the “actual rotation” will smoothly get to the “target rotation” instead of abruptly teleporting.

I got your suggestion to work, however the smoothing makes precision aiming very hard and annoying, is there a way to exclusively apply the smoothing whenever the camera is being returned to the set boundary?