Hello everyone,

I am verry new to godot and gdscript and i am trying to make a 2d isometric survival rpg game.

Now i have come to the point where i can cut a tree down and when it does that i want my sticks scene to be spawned multiple times but between a random number of 3 and 7.

I got it to the point that when the trees health reaches 0 it goes away and 1 stick wil spawn, I just dont know how to make multiple spawn.

This is what i have now

Welcome to the forums @Nyssa!

To spawn multiple instances, I would suggest using a for loop, and then spawning the sticks using that loop. You can also apply an offset in the loop, so all the sticks are not on top of each other (optionally). Something like this:

func kill():
	var number_of_sticks = round(rand_range(3, 7))
	for i in range(0, number_of_sticks):
		var stick_instance = sticks_scene.instance()
		get_parent().add_child(stick_instance)
		stick_instance.global_position = global_position
		# optional: add offset
		stick_instance.global_position += Vector2(rand_range(-64, 64), rand_range(-64, 64))
		print ("Stick ", i, " made!")

Thanks you so much, this worked like a charm!

2 years later