0 votes

In my Top-down shooting game, I have an array of enemy like this:

var normalenemy = preload("res://scenes/normalEnemy.tscn")
var runner
enemy = preload("res://scenes/runnerEnemy.tscn")
var flyingenemy = preload("res://scenes/flyingEnemy.tscn")
var grabber
enemy = preload("res://scenes/grabberEnemy.tscn")
var tanker_enemy = preload("res://scenes/tankerEnemy.tscn")

var enemieslist = [normalenemy, runnerenemy, flyingenemy, grabberenemy, tankerenemy]

The problem is I want "grabber" enemy to exist on the map one at a time (for balancing reason, think it's like a mini boss). I can check if it is still on the map but is there any idea or logic how to temporary prevent the program to randomize and spawn more "grabber" if there is one on the map (all enemies are spawned as instance node) and let the program randomly spawn a new one if the one on the map is dead.

Godot version Godot 3.5
in Engine by (12 points)

1 Answer

0 votes

Pick a random enemy, change if it shouldn't spawn (add in logic to check existence of grabber):

var choosen_enemy = null
while choosen_enemy == null:
    choosen_enemy = enemies_list[randi() % enemies_list.size()]
    if is_grabber_on_map and choosen_enemy == grabber_enemy:
        choosen_enemy = null
var new_enemy = choosen_enemy.instance()

Small tip: mark your code using {} button, it helps others help you :)

by (1,100 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.