spawning chests in csg boxes, working on making them root of scene so they aren't cleared with the scene on exit

This commit is contained in:
derek
2025-04-04 16:30:51 -05:00
parent 6cd06193b5
commit ce08df66e6
15 changed files with 99 additions and 76 deletions

24
scripts/sublevel.gd Normal file
View File

@@ -0,0 +1,24 @@
extends Node3D
const CHEST_1 = preload("res://chest1.tscn")
func _ready() -> void:
spawn_chests()
func spawn_chests():
var chest_spawners = get_tree().get_nodes_in_group("chest_spawner")
if chest_spawners.size() > 0:
for i in chest_spawners:
i.visible = false
var number_chests = 3
while number_chests > 0:
var chest_loc = chest_spawners.pick_random()
var instance_chest = CHEST_1.instantiate()
get_tree().current_scene.add_child(instance_chest)
instance_chest.global_position = chest_loc.global_position + chest_loc.random_box_pos()
print("CHEST SPAWNED AT : ",instance_chest.global_position)
number_chests -= 1