diff --git a/src/empty_space_thing.gd b/src/empty_space_thing.gd index 6b6fab2..e661fe4 100644 --- a/src/empty_space_thing.gd +++ b/src/empty_space_thing.gd @@ -9,7 +9,9 @@ var velocity: float = 0 # variables for velocity calculation var mouse_first_location: Vector2 +var mouse_last_location: Vector2 var mouse_release_location: Vector2 +var mouse_n_minus_one_location: Vector2 var time_since_first_location: float = -1 # Export variables, for ease of setting without going into the code @@ -24,14 +26,16 @@ 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() + global_position.x += -(mouse_last_location.x - mouse_first_location.x) elif Input.is_action_just_released("click"): time_since_first_location += delta @@ -48,18 +52,21 @@ func _process(delta: float) -> void: velocity = (distance / (velocity_coeffecient * delta)) draggable = false - - elif not draggable: - # when the drag is complete, create a tween to ease out towards zero - var tween = get_tree().create_tween() - tween.tween_property(self, "velocity", 0, ease_out_time).set_ease(Tween.EASE_OUT) - mouse_first_location = Vector2(0,0) - mouse_release_location = Vector2(0,0) - draggable = true + + # when the drag is complete, create a tween to ease out towards zero + var tween = get_tree().create_tween() + + tween.tween_property(self, "velocity", + 0, ease_out_time).set_ease(Tween.EASE_OUT) + + mouse_first_location = Vector2(0,0) + mouse_release_location = Vector2(0,0) + + draggable = true if global_position.x > max_x: push_warning("too far to the pos_x") - velocity = 0 + velocity = -velocity global_position.x = 999 time_since_first_location = -1 draggable = true @@ -67,8 +74,10 @@ func _process(delta: float) -> void: elif global_position.x < min_x: push_warning("too far to the neg_y") - velocity = 0 + velocity = -velocity global_position.x = 1 time_since_first_location = -1 draggable = true return + + mouse_last_location = get_global_mouse_position() diff --git a/src/scroll_root.tscn b/src/scroll_root.tscn index 1143f22..46d25cc 100644 --- a/src/scroll_root.tscn +++ b/src/scroll_root.tscn @@ -23,4 +23,4 @@ offset_top = 299.0 offset_right = 455.0 offset_bottom = 299.0 script = ExtResource("2_mej84") -velocity_coeffecient = 220 +velocity_coeffecient = 110