class_name PlayerCamera extends Camera3D var target var player_offset : Vector3 @export var decay = 0.9 # How quickly the shaking stops [0, 1]. @export var max_offset = Vector2(2, 1.5) # Maximum hor/ver shake in pixels. @export var noise : FastNoiseLite var noise_y = 0 var trauma = 0.0 # Current shake strength. var trauma_power = 2 # Trauma exponent. Use [2, 3]. func _enter_tree() -> void: call_deferred("register_player") func _ready() -> void: randomize() noise.seed = randi() func register_player() -> void: target = Game.player target.camera = self if target: player_offset = global_position - target.global_position func add_trauma(amount): trauma = min(trauma + amount, 1.0) func _process(delta: float) -> void: if target: global_position = target.global_position + player_offset if trauma: trauma = max(trauma - decay * delta, 0) shake() else: h_offset = 0 v_offset = 0 func shake(): noise_y += .1 var amount = pow(trauma, trauma_power) var n_val = noise.get_noise_2d(noise.seed*2, noise_y) h_offset = max_offset.x * amount * randf_range(-1, 1) v_offset = max_offset.y * amount * randf_range(-1, 1) print("%f %f" % [h_offset, v_offset])