3D camera rotation with keyboad delay

Godot Version

4.3

Question

Hello!

I’m trying to rotate a 3d first person camera with the keyboard (like in old 3d games).
but when I test it there is always a delay when pressing the keys and when several keys are played at the same time.
I can’t use internet solutions because all of them are for mouse, and i need to move the camera with the keyboard.

Can someone tell me how to do it?

Thank you.

@onready var camarapivot: Node3D = $camarapivot

var sencibilidad = 0.05

func _input(delta):
	if Input.is_action_pressed("ui_left"):
		rotate_y(sencibilidad)
	if Input.is_action_pressed("ui_right"):
		rotate_y(-sencibilidad)
	if Input.is_action_pressed("ui_up"):
		camarapivot.rotate_x(sencibilidad)
	if Input.is_action_pressed("ui_down"):
		camarapivot.rotate_x(-sencibilidad)
	camarapivot.rotation.x = clampf(camarapivot.rotation.x, -deg_to_rad(80), deg_to_rad(80))

A better way would be to check in your physics process loop for input and change your cameras rotation like you would for your characters position:

@onready var cam : Node3D = $MyCamera
const cam_sens : float = 100

func _physics_process(delta):
   rotation.y += Input.get_axis("cam_left", "cam_right") * delta * cam_sens
   cam.rotation_degrees.x = clamp(cam.rotation_degrees.x + delta * Input.get_axis("cam_down", "cam_up") * cam_sens, -80, 80)