From 70522c38af7d241e7144761e7f21b8a97e726d93 Mon Sep 17 00:00:00 2001 From: Logan Date: Sat, 1 Oct 2022 12:16:05 -0600 Subject: Prevent camera from zooming too far out. --- scripts/camera.gd | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'scripts/camera.gd') diff --git a/scripts/camera.gd b/scripts/camera.gd index de8b20c..f44e430 100644 --- a/scripts/camera.gd +++ b/scripts/camera.gd @@ -4,8 +4,20 @@ onready var basketball = $"../Basketball" onready var hoop = $"../Hoop" func _process(_delta): - position = (basketball.position + hoop.position) / 2 - if (basketball.position.distance_to(hoop.position) + (basketball.drag_radius * 3)) > limit_right: + if !basketball.waiting_for_shoot: + position = (basketball.position + hoop.position) / 2 + adjust_zoom() + +func adjust_zoom(): + if !basketball.waiting_for_shoot and (basketball.position.distance_to(hoop.position) + (basketball.drag_radius * 3)) > limit_right: set_zoom(Vector2(1, 1) * ((basketball.position.distance_to(hoop.position) + (basketball.drag_radius * 3)) / limit_right)) + elif basketball.waiting_for_shoot and (basketball.start_position.distance_to(hoop.position) + (basketball.drag_radius * 3)) > limit_right: + set_zoom(Vector2(1, 1) * ((basketball.start_position.distance_to(hoop.position) + (basketball.drag_radius * 3)) / limit_right)) else: set_zoom(Vector2(1, 1)) + var zoom_level = get_zoom() + set_zoom(Vector2(clamp(zoom_level.x, 1, 1.94), clamp(zoom_level.y, 1, 1.94))) + +func _on_Basketball_reset(): + position = (basketball.start_position + hoop.position) / 2 + adjust_zoom() -- cgit v1.2.3