Enemy random spawn

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Drai3Seltor

Hi, I am new to coding, but I am learning quickly and I am finishing my first 2D rpg level and as the final boss I wanted to put someone that would have spawn enemy at random location around him when hit.
It is going all good but during the script I put something like this:

var rand = 0
var randx = 0
var randy = 0

func _percentage():
	rand = rand_range(0,100)
	if rand > 90:
		randx = rand_range(-200, 200)
		randy = rand_range(-200, 200)
		var enemyscene = load("res://Enemy.tscn")
		var enemy = enemyscene.instance()
		enemy.position.x = randx
		enemy.position.y = randy

But then the enemy being child node of the boss move with him and so they are pretty useless.
How can I do to spawn an indipendent node?
Thank you very much

:bust_in_silhouette: Reply From: kidscancode

The simple solution to this is: don’t make the new enemy a child of the boss. Add it as a child to the world node, or whatever higher-level node you have in your scene.

actually that did not occured to me, and the answer is so easy.
Thank you a lot

Drai3Seltor | 2020-06-06 18:50