Godot Version
(Main scene)
func _on_enemy_spawn_timeout():
var spawn_x = rng.randf()
var spawn_y = rng.randi_range(0, 500)
var enemy = enemy_scene.instantiate()
if spawn_x > 0.5:
move_right.emit()
enemy.position = Vector2(0, spawn_y)
else:
move_left.emit()
enemy.position = Vector2(1400, spawn_y)
get_tree().current_scene.add_child(enemy)
(Enemy scene)
func _physics_process(delta):
if move_right == true:
position.x += 200 * delta
if move_left == true:
position.x -= 200 * delta
func _on_node_2d_move_left():
move_left = true
func _on_node_2d_move_right():
move_right = true
Question
I’m a total newbie so maybe this is stupid… I’m making a shmup where I want the enemy to move either left or right depending on which side of the screen they spawn on. I can’t seem to figure out how to control the enemies after they spawn. Can somebody give me some tips?