Camera jitter on the Y axis

Godot Version

Newest Version

Question

Im trying to make my own character controller using a rigidbody, the problem is the camera on the y axis is so jittery its unplayable

Heres the code:

 extends Node3D

@export var Speed : float
@onready var body = $RigidBody3D
@export var mouse_sensitivity : float
@onready var camera = $RigidBody3D/Head/Camera3D

func _ready():
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _input(event):
	if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
		body.rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
		camera.rotate_x(deg_to_rad(-event.relative.y * mouse_sensitivity))

func _physics_process(delta):
	handle_movement(delta)
	

	
func handle_movement(delta):
	var direction = Vector3.ZERO
	
	if Input.is_action_pressed("Up"):
		direction += Vector3.FORWARD
	if Input.is_action_pressed("Down"):
		direction += Vector3.BACK
	if Input.is_action_pressed("Left"):
		direction += Vector3.LEFT
	if Input.is_action_pressed("Right"):
		direction += Vector3.RIGHT
	
	if direction != Vector3.ZERO:
		direction = direction.normalized() * Speed
		body.apply_force(direction * delta)

You could modify a float with the relative mouse movement and use that as a target to lerp too.