Delayed camera rotation in first-person

I adjusted the code to be usable with movement as well and simplified it a bit :slight_smile: enjoy


obraz

extends CharacterBody3D

@export var camera: Node3D
var movement_speed: float = 150.0
var rotation_speed: float = 0.005
var ease_curve: float = 0.1
var target_rotation: Vector2

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

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		var mouse_motion_event: InputEventMouseMotion = event as InputEventMouseMotion
		target_rotation -= mouse_motion_event.relative * rotation_speed
		target_rotation.y = clampf(target_rotation.y, PI/-2, PI/2)

func _physics_process(delta: float) -> void:
	rotation.y = lerp_angle(rotation.y, target_rotation.x, ease(delta, ease_curve))
	camera.rotation.x = lerp_angle(camera.rotation.x, target_rotation.y, ease(delta, ease_curve))
	
	var movement_direction: Vector3 = Vector3.ZERO
	if Input.is_action_pressed("ui_up"):
		movement_direction += Vector3.FORWARD
	if Input.is_action_pressed("ui_down"):
		movement_direction += Vector3.BACK
	if Input.is_action_pressed("ui_right"):
		movement_direction += Vector3.RIGHT
	if Input.is_action_pressed("ui_left"):
		movement_direction += Vector3.LEFT
	
	velocity = basis * movement_direction * delta * movement_speed
	
	move_and_slide()