1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-26 01:54:23 +00:00
hella-farm/behaviours/move_physics.gd

40 lines
771 B
GDScript3
Raw Normal View History

2024-04-20 02:54:33 +00:00
extends Move
class_name MoveTowardsGravity
signal dragged(cursor: Cursor)
signal dropped
signal fallen
@export var acceleration = 2500.0
@export var linear_damp = 50.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)