Godot 4
hi! I try to make a 2D shooter game. Objects are not spawning, and I am not shure what I did wrong.
extends Timer
var cow_01 = preload("res://prefabs/Shooter/shooter_cow_01.tscn")
var coin_01 = preload("res://prefabs/Shooter/shooter_coin_01.tscn")
var coin_05 = preload("res://prefabs/Shooter/shooter_coin_05.tscn")
func _on_timeout():
randomize()
var colectables = [cow_01,cow_01,cow_01,cow_01,cow_01,coin_01,coin_01,coin_05]
var kinds = colectables[randi()% colectables.size()]
var spawner = kinds.instantiate()
#spawner.position = Vector2(randi_range(10,990), randi_range(10,590))
spawner.position = Vector2(randi_range(180,1200), randi_range(1750,1200))
add_child(spawner)
_move(spawner)
wait_time = randi_range(0,1)
func _move(spawner):
if spawner.position.y >= 0:
spawner.position.y -= 5
On the other note, how can I move them? I mean, I know how to move things around, I just don’t know how to give every child a direction they would follow till they end thier life cycle. My way makes them wiggle around x axis like they try to cause a triffic accident!
extends Sprite2D
var rnd = RandomNumberGenerator.new()
var horizontal_swift = rnd.randf_range(-100,2000)
func _process(delta):
_horizontal_swift()
if $".".position.y >= 0 && $".".position.y <= -100:
$".".position.y -= 10
func _horizontal_swift():
horizontal_swift = rnd.randf_range(-100,2000)
$".".position.x = horizontal_swift