From 13ed3035e3e40b62b2a91c4526b09a1529660dd9 Mon Sep 17 00:00:00 2001 From: Sharb Date: Mon, 15 Sep 2025 10:34:52 +0800 Subject: [PATCH 1/2] Attempt to create more accurate initial camera scroll --- Scripts/Parts/CameraHandler.gd | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Scripts/Parts/CameraHandler.gd b/Scripts/Parts/CameraHandler.gd index ffcbb55..56558a8 100644 --- a/Scripts/Parts/CameraHandler.gd +++ b/Scripts/Parts/CameraHandler.gd @@ -21,6 +21,9 @@ static var cam_locked := false var scrolling := false var cam_direction := 1 +# how far between the center and the edge of the screen before scrolling to the center +const SCROLL_DIFFERENCE := 48.0 + func _exit_tree() -> void: cam_locked = false @@ -46,6 +49,16 @@ func handle_camera(delta: float) -> void: do_limits() camera.global_position = camera_position + camera_offset + + # horizontal adjusgments + # if the position is matching the camera, start scrolling towards the center + if global_position.x >= camera_position.x: + position.x = move_toward(position.x,0.0,delta * 30.0) + else: + # if the camera if behind the middle of the screen, calculate the current difference + position.x = max(min(camera_position.x-global_position.x,SCROLL_DIFFERENCE),position.x) + + update_camera_barriers() func update_camera_barriers() -> void: @@ -67,14 +80,7 @@ func handle_horizontal_scrolling(delta: float) -> void: if global_position.x >= camera_position.x: var offset = 0 scrolling = true - if camera_position.x <= global_position.x - 4: - offset = camera_position.x - global_position.x + abs(true_velocity.x * delta) camera_position.x = global_position.x + offset - elif global_position.x >= camera_position.x - get_viewport_rect().size.x / 8: - if true_velocity.x > 75: - camera_position.x += true_velocity.x * delta / 2 - else: - camera_position.x += true_velocity.x * delta ## LEFT MOVEMENT elif true_vel_dir == -1 and can_scroll_left and Global.current_level.can_backscroll: @@ -82,14 +88,7 @@ func handle_horizontal_scrolling(delta: float) -> void: if global_position.x <= camera_position.x: scrolling = true var offset = 0 - if camera_position.x >= global_position.x + 4: - offset = camera_position.x - global_position.x - abs(true_velocity.x * delta) camera_position.x = global_position.x + offset - elif global_position.x <= camera_position.x + get_viewport_rect().size.x / 4: - if true_velocity.x < -75: - camera_position.x += true_velocity.x * delta / 2 - else: - camera_position.x += true_velocity.x * delta func handle_vertical_scrolling(_delta: float) -> void: From bbc061e6c35f971e508a60d73fb5e88a613b7151 Mon Sep 17 00:00:00 2001 From: Sharb Date: Mon, 15 Sep 2025 19:07:45 +0800 Subject: [PATCH 2/2] adjusted camera scroll to line up with the players speed --- Scripts/Parts/CameraHandler.gd | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Scripts/Parts/CameraHandler.gd b/Scripts/Parts/CameraHandler.gd index 56558a8..b90bec5 100644 --- a/Scripts/Parts/CameraHandler.gd +++ b/Scripts/Parts/CameraHandler.gd @@ -49,16 +49,6 @@ func handle_camera(delta: float) -> void: do_limits() camera.global_position = camera_position + camera_offset - - # horizontal adjusgments - # if the position is matching the camera, start scrolling towards the center - if global_position.x >= camera_position.x: - position.x = move_toward(position.x,0.0,delta * 30.0) - else: - # if the camera if behind the middle of the screen, calculate the current difference - position.x = max(min(camera_position.x-global_position.x,SCROLL_DIFFERENCE),position.x) - - update_camera_barriers() func update_camera_barriers() -> void: @@ -89,6 +79,14 @@ func handle_horizontal_scrolling(delta: float) -> void: scrolling = true var offset = 0 camera_position.x = global_position.x + offset + + # horizontal adjusgments + # if the position is matching the camera, start scrolling towards the center + if global_position.x >= camera_position.x: + position.x = move_toward(position.x,0.0,delta * max(30.0, abs(true_velocity.x / 2.3))) + else: + # if the camera if behind the middle of the screen, calculate the current difference + position.x = max(min(camera_position.x-global_position.x,SCROLL_DIFFERENCE),position.x) func handle_vertical_scrolling(_delta: float) -> void: