bm-frontend-defence/Source/SpawnTimer.gd
2022-01-28 00:35:46 +01:00

37 lines
695 B
GDScript3

extends Timer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var attackerScene = preload("res://attacker.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _timeout():
print("timer")
var child = attackerScene.instance()
var width = get_viewport().size.x
var height = get_viewport().size.y
var rot = rand_range(0, PI*2)
var center = Vector2(width/2, height/2)
var vec = Vector2(-max(width, height)/2, 0)
vec = vec.rotated(rot) + center
vec = vec
child.rotation = rot
child.position = vec
child.target = center
child.speed = min(width, height)
add_child(child)