Struggling with rotating CharacterBody3D with mouse input

Godot Version

Godot 4.3.stable

Question

`I’m trying to make a 6DOF shooter (think of games like Descent and Forsaken) and I’m using a CharacterBody3D for the player. I have managed to set up some basic movement, but I’m facing problems with the mouse controls. Basically, I want the mouse to rotate the CharacterBody3D on it’s local X and Y axes. I managed to code that in, but I’m facing a problem. The code basically gets the mouse motion for both X and Y and then multiplies it by a variable called mouse_sensitivity (0.0005). It then sets the resulting values to their respective variables: rot_x and rot_y. It works well enough, but the problem is that I don’t know how to code it so that it defaults to 0 when the mouse is no longer being moved or a speed cap that prevents any additional. This means that the CharacterBody3D will get insanely fast if I move my mouse very fast in one direction and not slow down to a complete stop when I stop moving my mouse. Can some at least give me some guidance on how I can code in both a speed cap and a way for the speed to smoothly reset back to 0?

Code for the mouse movement below:

#note: this snipped of my code only includes the lines involving mouse movement. Other code has been removed for readability.

var rot_x: float
var rot_y: float

var mouse_sensitivity = 0.0005

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

func _input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		rot_x -= event.relative.x * mouse_sensitivity
		rot_y -= event.relative.y * mouse_sensitivity
		print(rot_x , "," , rot_y)
	

func _physics_process(delta: float) -> void:

#code for the basic movement not included here for readability.
	
	rotate(transform.basis.y.normalized(), rot_x)
	rotate(transform.basis.x.normalized(), rot_y)

My reply in this thread about rotating a camera might help you.

For the speed cap you can use a setter and clampf e.g.

var rot_x: float:
    set(value):
        # change min and max (-1 and 1 in this example) to whatever values make sense for your game
        rot_x = clampf(value, -1, 1)