0 votes
extends Node2D

var y = 0
# var b = "text"

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var enemy1 = preload("res://enemy1.tscn")

# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    pass


func _on_Timer_timeout():
        y-=100
        print(y)
        var instance = enemy1.instance()
        instance.position = Vector2(0, y)
        add_child(instance)
        $Timer.start()

This is what I have so far. This script is connected to a Node2D and it's supposed to spawn an enemy a little higher then the last one. It doesn't work and I don't know why...
Help?

Godot version 3.4
in Engine by (18 points)
func _on_Timer_timeout():
    y-=100
    print(y)
    var instance = enemy1.instance()
    instance.position = Vector2(0, y)
    add_child(instance)
    $Timer.start()
    // try 
   print(instance.global_position)

When you say It doesn't work, what does that mean? For example:

  • The _on_Timer_timeout() function isn't firing?
  • The enemy doesn't spawn?
  • The enemy spawns, but not in the expected location?
  • Something else entirely?

the enemy spawns but not in the expected position. The enemy spawns in the same location as the previous enemy.

1 Answer

0 votes

The problem was that I tried to do it on a node that had animation. I am dumb. I know. Sorry for wasting your time!

by (18 points)
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.