I think you can change the transform after calling add_child
, if I remember correctly.
From what I have gathered looking online, it looks like your code should work though. Are you checking the position in _ready
on the spawned asteroid? Also, are you sure that spawn_position
is not (0, 0, 0)
?
Maybe try the following code, though I'm not sure if it will work not:
func spawn_asteroid():
var spawn_position : Vector3 = get_spawn_position()
var asteroid_instance = asteroid_scene.instance()
spawned_asteroids.append(asteroid_instance)
add_child(asteroid_instance)
asteroid_instance.transform.origin = spawn_position
# Something you can try is move the code in _ready on your asteroid to a function
# called _setup, and then use the following line of code:
# asteroid_instance._setup()
The code above should change the position of the asteroid to the position in spawn_position
, though if you are checking or changing the asteroid position in the _ready
function of the asteroid script, you might need to make adjustments.
That is strange that the position is not being updated. I remember I have had this issue before, but I think I just worked around it by using an additional function.