grunk/src/props/physics/holdable.gd

26 lines
753 B
GDScript3
Raw Normal View History

class_name Holdable extends Node
## Component for holdable elements
@export var hold_distance := 1.0
2025-07-04 14:56:35 -06:00
@export var controller: RigidBody3D
2025-07-04 14:56:35 -06:00
func _ready() -> void:
if not controller:
controller = get_parent() as RigidBody3D
assert(controller, "Holdable %s must be a child of a RigidBody3D" % str(self))
controller.add_user_signal(Interactive.SELECT_SIGNAL)
controller.connect(Interactive.SELECT_SIGNAL, select)
controller.add_user_signal(Interactive.ACTIVATE_SIGNAL)
controller.connect(Interactive.ACTIVATE_SIGNAL, activate)
func select() -> void:
Player.instance.hud.hold_hud.select_prop()
func activate() -> void:
if not Player.instance.hold_component.holding_object():
Player.instance.hold_component.attach(controller, hold_distance)