Initial commit

This commit is contained in:
2026-01-21 23:51:53 +01:00
commit 60b208fee0
1703 changed files with 100223 additions and 0 deletions

31
script/objectSpawner.gd Normal file
View File

@@ -0,0 +1,31 @@
extends Node3D
class_name ObjectSpawner
@export var Objects: Array[RandomObject]
@export var Parent: Node
var weightArray: PackedFloat32Array
var rng = RandomNumberGenerator.new()
func _ready():
if Objects.is_empty(): return
var spaceship = get_node("/root/Main/Maps/Spaceship")
for obj in Objects: #Init weight array
weightArray.push_back(obj.probability)
var objectReference = load(Objects[rng.rand_weighted(weightArray)].dir) #Get random Object depending on weights
var ObjectInstance = objectReference.instantiate()
if Parent:
Parent.call_deferred("add_child",ObjectInstance) #Adds Object instance
elif spaceship:
spaceship.call_deferred("add_child",ObjectInstance)
else:
push_error("Object Spawner failed to spawn object because of missing parent node")
ObjectInstance.rotation = self.global_rotation
ObjectInstance.position = self.global_position
self.queue_free()