I'm learning and creating my fist game - space asteroid shooter. I have a problem with spawning asteroid.
This is my scene cdoe
extends Node2D
onready var small = preload("res://Scenes/SmallAsteroid.tscn")
func _ready():
var timer = Timer.new()
timer.set_wait_time(rand_range(0, 3))
timer.set_one_shot(false)
timer.connect("timeout", self, "add_asteroid")
add_child(timer)
timer.start()
func add_asteroid():
add_child(small.instance())
and this is my asteroid code:
extends RigidBody2D
export (int) var MAX_SPEED = 1
onready var viewportSize = get_viewport().size
var destinationPoint = Vector2.ZERO
func _ready():
position = Vector2(rand_range(-400, 400), rand_range(-400, 400))
destinationPoint = Vector2(rand_range(-400, 400), rand_range(-400, 400))
func _process(delta):
position.x += destinationPoint.x * MAX_SPEED * delta
position.y += destinationPoint.y * MAX_SPEED * delta
What is the effect in the game ?
Asteroid is spawn every 1 second, then they wait 1 second and then they move. But why they wait additional second to move ?