need help making this code work. I’m trying to make enemies spawn on 2 spawners on the left and the right. I’m trying to spawn enemies on the global position of these spawners which I get from .globalposition. I used global position before with no error so I really don’t know why sometimes it works and sometimes does not.
var spawn_left = Leftspawn.global_position
var spawn_right = Rightspawn.global_position
var score
func newgame():
pass
func _process(delta):
pass
func _on_rightspawntimer_timeout():
var new_enemy = ENEMY.instantiate()
get_tree().current_scene.add_child(new_enemy)
new_enemy.global_position = spawn_right
func _on_leftspawnertimer_timeout():
var new_enemy = ENEMY.instantiate()
get_tree().current_scene.add_child(new_enemy)
new_enemy.global_position = spawn_left
i am reading ENEMY so I assume it’s a const which is a bad idea because it’s actually a packedScene resource that needs to be loaded in on runtime for example like this: var ENEMY = load("PATH-TO-ENEMY.tscn")
I would first set a breakpoint at var new_enemy = ENEMY.instantiate() and then see if new_enemy stays null or has an actual value
THanks for the suggestions but i was starting to be annoyed so I brute forced this problem by putting in the literal cords of the sprites as a variable and fixed this. i will try the on ready solution and see if it works on other things .