2024-04-20 02:54:33 +00:00
|
|
|
extends Move
|
2024-04-20 02:55:09 +00:00
|
|
|
class_name MovePhysics
|
2024-04-20 02:54:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
signal dragged(cursor: Cursor)
|
|
|
|
signal dropped
|
|
|
|
signal fallen
|
|
|
|
|
|
|
|
|
2024-04-21 22:56:35 +00:00
|
|
|
@export var acceleration = 1250.0
|
|
|
|
@export var drag_damp = 0.4
|
|
|
|
@export var drop_damp = 0.05
|
|
|
|
@export var drop_epsilon = 16.0
|
2024-04-20 02:54:33 +00:00
|
|
|
|
|
|
|
var cursor: Cursor = null
|
2024-04-21 22:56:35 +00:00
|
|
|
var falling: bool = false
|
2024-04-20 02:54:33 +00:00
|
|
|
|
|
|
|
var velocity := Vector2.ZERO
|
|
|
|
|
|
|
|
|
|
|
|
func drag(value: Cursor) -> void:
|
|
|
|
cursor = value
|
|
|
|
dragged.emit(value)
|
|
|
|
|
|
|
|
func drop() -> void:
|
|
|
|
cursor = null
|
2024-04-21 22:56:35 +00:00
|
|
|
falling = true
|
2024-04-20 02:54:33 +00:00
|
|
|
dropped.emit()
|
|
|
|
|
|
|
|
func fall() -> void:
|
|
|
|
velocity = Vector2.ZERO
|
2024-04-21 22:56:35 +00:00
|
|
|
falling = false
|
2024-04-20 02:54:33 +00:00
|
|
|
fallen.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if enabled:
|
|
|
|
if cursor:
|
|
|
|
var gap = cursor.global_position - global_position
|
|
|
|
velocity += gap * delta * acceleration
|
2024-04-21 22:56:35 +00:00
|
|
|
velocity *= 1.0 - drag_damp
|
|
|
|
else:
|
|
|
|
velocity *= 1.0 - drop_damp
|
|
|
|
if falling and velocity.length() < drop_epsilon:
|
|
|
|
fall()
|
2024-04-20 02:54:33 +00:00
|
|
|
move.emit(velocity * delta)
|