offset now works
This commit is contained in:
@@ -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
|
||||
@@ -49,17 +53,20 @@ func _process(delta: float) -> void:
|
||||
(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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user