0 votes

I have an enemy spawner and it works really good, it picks a random enemy from a list of enemies and spawns it at the position I input. I can randomize the spawning frequency and position but the problem starts here. I want enemies to spawn randomly but not too close to player. When I try telling it to randomize position until it's far enough from player and it works most of time but it sometimes causes stack overflows.

My only idea is using a randomizer to pick a number from 1 to 4 and spawn an enemy in corresponding side(Left, Right, Up, Down) with enough gap between player and enemy but I don't want to use a bunch of if else statements(I did it before and code gets too messy and unnecessarily long). There must be an easier way to do things, can someone help with finding a solution maybe link a documentation or a video, or just explain themselves

Godot version latest
in Engine by (70 points)

1 Answer

+1 vote

Here is one idea I learned from a GDQuest tutorial (see from 32:20):

The idea is to make a big spawning circle around the player by using a Path2D node (though a code is needed to make a round circle).

by (46 points)

Yeah I think it does the job, thank you so much

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.