Camera Movement with Mouse

Godot Version

4.7.1

Question

I am new to Game Development, and I have been fighting this code for at least an hour now, all I want is to Move my camera with my mouse like any other game in existence

extends CharacterBody3D


const SPEED = 5.0
const JUMP_VELOCITY = 4.5
const SENSITIVITY = 0.03

@onready var Head = $Head
@onready var Camera = $Head/Camera3D

var pos = get_global_mouse_position()


func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta

func _ready():
	Input.set.mouse.mode(Input.MOUSE.MODE.CAPTURED)
	
func _unhandled_input(Event):
	if Event is InputEventMouseMotion:
		head.rotate_y(-event.relative.x * SENSITIVITY)
		camera.rotate_x(-event.relative.y * SENSITIVITY)
	
	# Handle jump.
	if Input.is_action_just_pressed("Jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir := Input.get_vector("Left", "Right", "Forward", "Backward")
	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		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)

	move_and_slide()

You forgot to describe the problem.

Btw move_and_slide() is always supposed to be called form _physics_process()

There are lots of YouTube tutorial videos on the subject of character movement. Start there.

There’s an amazing tutorial made by Octodemy specifically for mouse camera. You can follow this tutorial to make your own.

Octodemy mouse camera tutorial