From f10c4aab1c669e9d0365ca31a49ecce8ecdb2919 Mon Sep 17 00:00:00 2001 From: Gabriella Date: Tue, 21 Oct 2025 11:31:14 -0600 Subject: [PATCH] enhancement: add toggle to "bounce" when X position is exceeded --- src/empty_space_thing.gd | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/empty_space_thing.gd b/src/empty_space_thing.gd index e661fe4..38fa36c 100644 --- a/src/empty_space_thing.gd +++ b/src/empty_space_thing.gd @@ -19,6 +19,7 @@ var time_since_first_location: float = -1 @export var max_x: int = 1000 @export var min_x: int = 0 @export var ease_out_time: float = 0.5 +@export var bounce: bool = false func _ready() -> void: draggable = true @@ -26,12 +27,10 @@ func _ready() -> void: func _process(delta: float) -> void: global_position.x += velocity - var offset: Vector2 if draggable: if (Input.is_action_just_pressed("click")): mouse_first_location = get_global_mouse_position() offset = get_local_mouse_position() - global_position - time_since_first_location = 0 if Input.is_action_pressed("click"): mouse_first_location = get_global_mouse_position() @@ -64,17 +63,19 @@ func _process(delta: float) -> void: draggable = true - if global_position.x > max_x: - push_warning("too far to the pos_x") - velocity = -velocity + if global_position.x >= max_x && velocity > 0: + if bounce: + velocity = -(velocity) + print("velocity negated, bouncing") global_position.x = 999 time_since_first_location = -1 draggable = true return - elif global_position.x < min_x: - push_warning("too far to the neg_y") - velocity = -velocity + elif global_position.x < min_x && velocity < 0: + if bounce: + velocity = -(velocity) + print("velocity negated, bouncing") global_position.x = 1 time_since_first_location = -1 draggable = true