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

54 lines
1,000 B
GDScript3
Raw Normal View History

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
2024-04-22 21:29:49 +00:00
@export var fly_damp = 0.045
@export var drop_damp = 0.2
@export var fly_cutoff = 400.0
@export var drop_cutoff = 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:
2024-04-22 21:29:49 +00:00
if velocity.length() >= fly_cutoff:
velocity *= (1.0 - fly_damp)
else:
velocity *= (1.0 - drop_damp)
if falling and velocity.length() < drop_cutoff:
2024-04-21 22:56:35 +00:00
fall()
2024-04-20 02:54:33 +00:00
move.emit(velocity * delta)