TinyAdventure/objects/item_spawner.gd

17 lines
561 B
GDScript
Raw Normal View History

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:
if randf() < spawn_chance:
var pickup_item:PickupItem = pickup_item_scene.instantiate()
2024-11-15 11:05:32 +01:00
pickup_item.item = load("res://data/items/seeds.tres")
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