How to change position of a scene instance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Forecaster1310
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?

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)

ramazan | 2022-02-28 15:53

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?

jgodfrey | 2022-02-28 16:15

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

Forecaster1310 | 2022-02-28 17:32

:bust_in_silhouette: Reply From: Forecaster1310

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!