diff --git a/scenes/blocks/dropped_block.gd b/scenes/blocks/dropped_block.gd index 867ae6c..818ad47 100644 --- a/scenes/blocks/dropped_block.gd +++ b/scenes/blocks/dropped_block.gd @@ -7,8 +7,10 @@ const PREFAB: PackedScene = preload("res://scenes/blocks/dropped_block.tscn") ## The amount of time to wait before PickupArea is set to monitorable[br] ## This is to ensure that the item isn't picked up immediately after throwing @export var pickup_timeout: int = 1 +@export var lifetime_in_seconds: int = 10 ## Lifetime before despawning @export var animation_player: AnimationPlayer @export var block_mesh: BlockMesh +@export var lifetime_timer: Timer @export var pickup_area: Area3D var id: String @@ -16,6 +18,8 @@ var impulse: Vector3 = Vector3.ZERO func _ready() -> void: + lifetime_timer.timeout.connect(_on_lifetime_timeout) + ## AnimationPlayer handles modifying BlockMesh scale, position, and rotation ## The scale is NOT applied to any other node, including RigidBody and CollisionShape animation_player.play("start_animation") @@ -40,6 +44,8 @@ func initialize(block_id: String, start_position: Vector3, drop_direction: Vecto impulse = drop_direction * drop_impulse apply_central_impulse(impulse) + lifetime_timer.start(lifetime_in_seconds) + func set_id(block_id: String) -> void: id = block_id if id in DBItems.data: @@ -48,6 +54,9 @@ func set_id(block_id: String) -> void: printerr("Unknown Block ID: ", id) +func _on_lifetime_timeout() -> void: + call_deferred("queue_free") + func _on_pickup_area_body_entered(body: Node3D) -> void: if not body is Player: return diff --git a/scenes/blocks/dropped_block.tscn b/scenes/blocks/dropped_block.tscn index a2fe66a..0281889 100644 --- a/scenes/blocks/dropped_block.tscn +++ b/scenes/blocks/dropped_block.tscn @@ -96,11 +96,12 @@ _data = { [sub_resource type="SphereShape3D" id="SphereShape3D_5kft2"] -[node name="DroppedBlock" type="RigidBody3D" node_paths=PackedStringArray("animation_player", "block_mesh", "pickup_area")] +[node name="DroppedBlock" type="RigidBody3D" node_paths=PackedStringArray("animation_player", "block_mesh", "lifetime_timer", "pickup_area")] collision_layer = 4 script = ExtResource("1_y8usf") animation_player = NodePath("AnimationPlayer") block_mesh = NodePath("BlockMesh") +lifetime_timer = NodePath("LifetimeTimer") pickup_area = NodePath("PickupArea") [node name="AnimationPlayer" type="AnimationPlayer" parent="."] @@ -129,4 +130,8 @@ shape = SubResource("SphereShape3D_5kft2") [node name="SaveDataComponent" parent="." instance=ExtResource("3_ix4xk")] save_data_resource = ExtResource("4_8xfh1") +[node name="LifetimeTimer" type="Timer" parent="."] +wait_time = 10.0 +one_shot = true + [connection signal="body_entered" from="PickupArea" to="." method="_on_pickup_area_body_entered"]