camera: added smooth camera zooming

This commit is contained in:
Simon Ward 2026-01-26 15:45:50 +13:00
parent cf14e5d398
commit 626fc3d752

View file

@ -7,8 +7,10 @@ var locked_mouse_positon = Vector2(0,0)
var mouse_locked = false var mouse_locked = false
var mouse_x_velocity = 0 var mouse_x_velocity = 0
var mouse_y_velocity = 0 var mouse_y_velocity = 0
var zoom_min = 4 var zoom_min = 4
var zoom_max = 100 var zoom_max = 80
var zoom_speed = 20
var current_zoom = 8 var current_zoom = 8
func reset(): func reset():
@ -27,9 +29,9 @@ func _input(event):
mouse_x_velocity = event.relative.x mouse_x_velocity = event.relative.x
mouse_y_velocity = event.relative.y mouse_y_velocity = event.relative.y
elif event.is_action_pressed("zoom_out"): elif event.is_action_pressed("zoom_out"):
current_zoom += 5 current_zoom += 1
elif event.is_action_pressed("zoom_in"): elif event.is_action_pressed("zoom_in"):
current_zoom -= 5 current_zoom -= 1
func _process(delta): func _process(delta):
# rotate outer gimbal around y axis # rotate outer gimbal around y axis
@ -65,4 +67,7 @@ func _process(delta):
reset() reset()
current_zoom = clamp(current_zoom, zoom_min, zoom_max) current_zoom = clamp(current_zoom, zoom_min, zoom_max)
$InnerGimbal/Camera3D.position = Vector3($InnerGimbal/Camera3D.position.x, current_zoom, current_zoom)
$InnerGimbal/Camera3D.position.x = $InnerGimbal/Camera3D.position.x
$InnerGimbal/Camera3D.position.y = lerp($InnerGimbal/Camera3D.position.y, float(current_zoom), zoom_speed*delta)
$InnerGimbal/Camera3D.position.z = lerp($InnerGimbal/Camera3D.position.z, float(current_zoom), zoom_speed*delta)