offset now works
This commit is contained in:
@@ -9,7 +9,9 @@ var velocity: float = 0
|
|||||||
|
|
||||||
# variables for velocity calculation
|
# variables for velocity calculation
|
||||||
var mouse_first_location: Vector2
|
var mouse_first_location: Vector2
|
||||||
|
var mouse_last_location: Vector2
|
||||||
var mouse_release_location: Vector2
|
var mouse_release_location: Vector2
|
||||||
|
var mouse_n_minus_one_location: Vector2
|
||||||
var time_since_first_location: float = -1
|
var time_since_first_location: float = -1
|
||||||
|
|
||||||
# Export variables, for ease of setting without going into the code
|
# Export variables, for ease of setting without going into the code
|
||||||
@@ -24,14 +26,16 @@ 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
|
||||||
time_since_first_location = 0
|
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()
|
||||||
|
global_position.x += -(mouse_last_location.x - mouse_first_location.x)
|
||||||
|
|
||||||
elif Input.is_action_just_released("click"):
|
elif Input.is_action_just_released("click"):
|
||||||
time_since_first_location += delta
|
time_since_first_location += delta
|
||||||
@@ -48,18 +52,21 @@ func _process(delta: float) -> void:
|
|||||||
velocity = (distance /
|
velocity = (distance /
|
||||||
(velocity_coeffecient * delta))
|
(velocity_coeffecient * delta))
|
||||||
draggable = false
|
draggable = false
|
||||||
|
|
||||||
elif not draggable:
|
# when the drag is complete, create a tween to ease out towards zero
|
||||||
# when the drag is complete, create a tween to ease out towards zero
|
var tween = get_tree().create_tween()
|
||||||
var tween = get_tree().create_tween()
|
|
||||||
tween.tween_property(self, "velocity", 0, ease_out_time).set_ease(Tween.EASE_OUT)
|
tween.tween_property(self, "velocity",
|
||||||
mouse_first_location = Vector2(0,0)
|
0, ease_out_time).set_ease(Tween.EASE_OUT)
|
||||||
mouse_release_location = Vector2(0,0)
|
|
||||||
draggable = true
|
mouse_first_location = Vector2(0,0)
|
||||||
|
mouse_release_location = Vector2(0,0)
|
||||||
|
|
||||||
|
draggable = true
|
||||||
|
|
||||||
if global_position.x > max_x:
|
if global_position.x > max_x:
|
||||||
push_warning("too far to the pos_x")
|
push_warning("too far to the pos_x")
|
||||||
velocity = 0
|
velocity = -velocity
|
||||||
global_position.x = 999
|
global_position.x = 999
|
||||||
time_since_first_location = -1
|
time_since_first_location = -1
|
||||||
draggable = true
|
draggable = true
|
||||||
@@ -67,8 +74,10 @@ func _process(delta: float) -> void:
|
|||||||
|
|
||||||
elif global_position.x < min_x:
|
elif global_position.x < min_x:
|
||||||
push_warning("too far to the neg_y")
|
push_warning("too far to the neg_y")
|
||||||
velocity = 0
|
velocity = -velocity
|
||||||
global_position.x = 1
|
global_position.x = 1
|
||||||
time_since_first_location = -1
|
time_since_first_location = -1
|
||||||
draggable = true
|
draggable = true
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mouse_last_location = get_global_mouse_position()
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ offset_top = 299.0
|
|||||||
offset_right = 455.0
|
offset_right = 455.0
|
||||||
offset_bottom = 299.0
|
offset_bottom = 299.0
|
||||||
script = ExtResource("2_mej84")
|
script = ExtResource("2_mej84")
|
||||||
velocity_coeffecient = 220
|
velocity_coeffecient = 110
|
||||||
|
|||||||
Reference in New Issue
Block a user