breakable barrels

This commit is contained in:
2026-08-28 19:02:19 +03:00
parent 1021a07b04
commit 1eb06876e9
17 changed files with 4160 additions and 9 deletions
+23
View File
@@ -0,0 +1,23 @@
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()