Compare commits

...

2 Commits

2 changed files with 8 additions and 4 deletions

View File

@@ -1,15 +1,18 @@
extends Control
class_name SpaceNode
# adapted from pc_tile code (project-elysium-main)
var initial_pos: Vector2
var offset: Vector2
var draggable: bool = false
var velocity: float = 0
# variables for velocity calculation
var mouse_first_location: Vector2
var mouse_release_location: Vector2
var time_since_first_location: float = -1
# Export variables, for ease of setting without going into the code
@export var velocity_coeffecient: int = 500
@export var max_x: int = 1000
@export var min_x: int = 0
@@ -28,7 +31,7 @@ func _process(delta: float) -> void:
time_since_first_location = 0
if Input.is_action_pressed("click"):
time_since_first_location += delta
mouse_first_location = get_global_mouse_position()
elif Input.is_action_just_released("click"):
time_since_first_location += delta
@@ -36,17 +39,18 @@ func _process(delta: float) -> void:
if mouse_release_location.x < mouse_first_location.x:
var distance = mouse_release_location.x - mouse_first_location.x
velocity = (distance /
(velocity_coeffecient * time_since_first_location))
(velocity_coeffecient * delta))
draggable = false
elif mouse_release_location.x > mouse_first_location.x:
var distance = abs(mouse_first_location.x
- mouse_release_location.x)
velocity = (distance /
(velocity_coeffecient * time_since_first_location))
(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)

View File

@@ -23,4 +23,4 @@ offset_top = 299.0
offset_right = 455.0
offset_bottom = 299.0
script = ExtResource("2_mej84")
velocity_coeffecient = 735
velocity_coeffecient = 220