Realistic camera lerp issues

Godot Version

4.3

Question

I’m trying to make camera those UE5 games have where the camera kind of lags behind the player mouse movement, I tried lerping it, but the Issue is that if i move my mouse too fast or far it starts spazzing out and rotating really fast

extends Node3D

@onready var camera = $Camera3D
@onready var head   = get_parent()

#settings
const sensitivity = .25
var target_x = 0.0
var target_y = 0.0

#misc
const sway_amount = .007

func _ready() -> void:
	#lock mouse
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _input(event) -> void:
	#unlock mouse
	if Input.is_action_just_pressed("ui_cancel"):
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	
	if event is InputEventMouseMotion:
		#main
		var delta = event.relative
		
		target_x -= delta.y * sensitivity
		target_y -= delta.x * sensitivity
	
		#misc
		#camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, -80, 80)
		#head.rotation.z = lerp(head.rotation.z, delta.x * sway_amount, .1)
	
func _process(delta: float) -> void:
	#head.rotation.z = lerp(head.rotation.z, 0.0, .1)
	
	camera.rotation_degrees.x = lerp(camera.rotation_degrees.x, target_x, .1)
	head.rotation_degrees.y   = lerp(head.rotation_degrees.y, target_y, .1)
	
	camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, -80, 80)

Here’s the link to the video of the spaz

You will want to use lerp_angle for rotations (in radians), since rotations wrap around from 0 to TAU you will need the special lerp to handle the fact that 1° and 359° are actually very close.