extends StaticBody3D # Preload the broken barrel scene const BARREL_BROKEN_SCENE = preload("res://tscn_s/BarrelBroken.tscn") func destroy_barrel(): # 1. Instantiate the broken pieces var broken_instance = BARREL_BROKEN_SCENE.instantiate() # 2. Place the fragments exactly where the intact barrel currently is broken_instance.global_transform = self.global_transform # 3. Add the fragments to the main game tree get_parent().add_child(broken_instance) # 4. (Optional) Apply a physics push to the fragments if you want an explosive effect for child in broken_instance.get_children(): if child is RigidBody3D: # Pushes pieces slightly outward and upward var random_direction = Vector3(randf_range(-1, 1), randf_range(0.5, 1.5), randf_range(-1, 1)).normalized() child.apply_central_impulse(random_direction * 5.0) # 5. Delete the intact barrel queue_free()