The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

i have a code to spawn a pillar to damage the player on the player's position
here is the code of the spawner

extends Node2D

var child_position
var current_pillars = 0
var pillar = preload("res://plant pillar.tscn").instance()

func _on_Timer_timeout():
    child_position = get_node("Position2D").position.x
    $".".position.x = child_position
    current_pillars + 1

        extends Position2D
        var pillar = preload("res://plant pillar.tscn").instance()

        func _process(delta):
            position.x = get_parent().get_parent().get_node("player").position.x

and here is the code for the pillar:

extends Area2D
var damage = 30
func _ready():
func _on_plant_pillar_body_entered(body):
    if body.is_in_group("players"):
func _on_Sprite_animation_finished():
    $CollisionShape2D.disabled = false
func _on_Timer2_timeout():

the biggest problem is that after the pillar is spawned for the first time he does not goes true the animation and so is already spwaned fully grown and the collision is set to true,
thank you

in Engine by (30 points)

1 Answer

+1 vote

You should get an error on every timeout after the first:

add_child: Can't add child [...] to [...], already has a parent [...]

If you want to add multiple pillars, you need to create multiple instances of it:

var pillar = preload("res://plant pillar.tscn")

func _on_Timer_timeout():
    # ...
    var new_pillar = pillar.instance()
    # ...

However, you're reusing the same instance over and over again!

by (10,634 points)

i absolutly love this community , thank you very much

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 Frequently asked questions and 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 [email protected] with your username.