34 lines
889 B
GDScript

extends Camera3D
@export_group("Zoom")
@export var zoom_speed := 0.5
@export var zoom_interpolation := 10.0
@export var zoom_min := 2.0
@export var zoom_max := 8.0
var target_distance: float
func _ready():
target_distance = position.z
Global.camera = self
func _input(event):
if event.is_action_pressed("zoom_in", true):
target_distance -= zoom_speed
on_distance_changed()
get_viewport().set_input_as_handled()
if event.is_action_pressed("zoom_out", true):
target_distance += zoom_speed
on_distance_changed()
get_viewport().set_input_as_handled()
func on_distance_changed():
target_distance = clampf(target_distance, zoom_min, zoom_max)
Global.camera_attributes.dof_blur_far_distance = target_distance + 1.0
func _process(delta):
if abs(target_distance - position.z) < 0.01:
return
position.z = lerpf(position.z, target_distance, zoom_interpolation * delta)