Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MemokingMH |
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