32 lines
807 B
GDScript
32 lines
807 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 _unhandled_input(event):
|
|
if event.is_action_pressed("zoom_in"):
|
|
target_distance -= zoom_speed
|
|
on_distance_changed()
|
|
|
|
if event.is_action_pressed("zoom_out"):
|
|
target_distance += zoom_speed
|
|
on_distance_changed()
|
|
|
|
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) |