enhancement: add toggle to "bounce" when X position is exceeded
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user