Inside of func _physics_process(delta)
you have the following section:
var input_dir = Vector2.ZERO
if mouse_captured:
input_dir = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
var cam_basis = Basis(Vector3.UP, yaw)
var direction = (cam_basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction != Vector3.ZERO:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
I believe this means that you are requiring direction
to be equal to Vector3(0,0,0) in order for the velocity of the CharacterBody3D to move towards 0 (i.e. stop). This is likely the cause of the character continuously moving as the input is likely to equal 0 often during regular mouse movement.
Could you describe the character and intended control/movement? Why was this initially implemented to always move the character?
Happy to try and help with more context!