2024-11-01 18:07:23 +01:00
|
|
|
class_name ItemSpawner
|
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
@export var item:ItemResource = null
|
|
|
|
@export var spawn_chance:float = 0.2
|
|
|
|
|
|
|
|
@onready var pickup_item_scene:PackedScene = preload("res://objects/pickup_item.tscn")
|
|
|
|
|
|
|
|
func spawn() -> void:
|
2024-11-17 22:00:24 +01:00
|
|
|
if spawn_chance >= 1.0 or randf() < spawn_chance:
|
2024-11-01 18:07:23 +01:00
|
|
|
var pickup_item:PickupItem = pickup_item_scene.instantiate()
|
2024-11-17 22:00:24 +01:00
|
|
|
pickup_item.item = item
|
2024-11-16 20:43:12 +01:00
|
|
|
pickup_item.world_item_initial_y_position = 0.5
|
|
|
|
pickup_item.world_item_initial_y_velocity = 3.0
|
2024-11-01 18:07:23 +01:00
|
|
|
get_parent().add_child(pickup_item)
|
|
|
|
pickup_item.global_transform = global_transform
|