1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 17:44:24 +00:00
hella-farm/behaviours/move_physics.gd

39 lines
770 B
GDScript

extends Move
class_name MoveTowardsGravity
signal dragged(cursor: Cursor)
signal dropped
signal fallen
@export var acceleration = 650.0
@export var linear_damp = 18.0
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)