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-20 02:54:56 +00:00
|
|
|
@export var acceleration = 650.0
|
|
|
|
@export var linear_damp = 18.0
|
2024-04-20 02:54:33 +00:00
|
|
|
|
|
|
|
var cursor: Cursor = null
|
|
|
|
|
|
|
|
var velocity := Vector2.ZERO
|
|
|
|
|
|
|
|
@onready var ticks_per_second = ProjectSettings.get_setting("physics/common/physics_ticks_per_second")
|
|
|
|
|
|
|
|
|
|
|
|
func drag(value: Cursor) -> void:
|
|
|
|
cursor = value
|
|
|
|
dragged.emit(value)
|
|
|
|
|
|
|
|
func drop() -> void:
|
|
|
|
cursor = null
|
|
|
|
dropped.emit()
|
|
|
|
|
|
|
|
func fall() -> void:
|
|
|
|
velocity = Vector2.ZERO
|
|
|
|
fallen.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if enabled:
|
|
|
|
if cursor:
|
|
|
|
var gap = cursor.global_position - global_position
|
|
|
|
velocity += gap * delta * acceleration
|
|
|
|
velocity *= 1.0 - linear_damp / ticks_per_second
|
|
|
|
move.emit(velocity * delta)
|