0 votes

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

in Engine by (17 points)

1 Answer

+3 votes

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.

by (20,913 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.