Compare commits

...

3 Commits

View File

@@ -19,6 +19,7 @@ var time_since_first_location: float = -1
@export var max_x: int = 1000 @export var max_x: int = 1000
@export var min_x: int = 0 @export var min_x: int = 0
@export var ease_out_time: float = 0.5 @export var ease_out_time: float = 0.5
@export var bounce: bool = false
func _ready() -> void: func _ready() -> void:
draggable = true draggable = true
@@ -26,12 +27,10 @@ func _ready() -> void:
func _process(delta: float) -> void: func _process(delta: float) -> void:
global_position.x += velocity global_position.x += velocity
var offset: Vector2
if draggable: if draggable:
if (Input.is_action_just_pressed("click")): if (Input.is_action_just_pressed("click")):
mouse_first_location = get_global_mouse_position() mouse_first_location = get_global_mouse_position()
offset = get_local_mouse_position() - global_position offset = get_local_mouse_position() - global_position
time_since_first_location = 0
if Input.is_action_pressed("click"): if Input.is_action_pressed("click"):
mouse_first_location = get_global_mouse_position() mouse_first_location = get_global_mouse_position()
@@ -64,18 +63,20 @@ func _process(delta: float) -> void:
draggable = true draggable = true
if global_position.x > max_x: if global_position.x >= max_x && velocity > 0:
push_warning("too far to the pos_x") if bounce:
velocity = -velocity velocity = -(velocity)/2
global_position.x = 999 print("velocity negated, bouncing")
global_position.x = max_x - 1
time_since_first_location = -1 time_since_first_location = -1
draggable = true draggable = true
return return
elif global_position.x < min_x: elif global_position.x < min_x && velocity < 0:
push_warning("too far to the neg_y") if bounce:
velocity = -velocity velocity = -(velocity)/2
global_position.x = 1 print("velocity negated, bouncing")
global_position.x = min_x + 1
time_since_first_location = -1 time_since_first_location = -1
draggable = true draggable = true
return return