I have a world map (rectangle 1920px, and 1280 high).
I have a player (Area2D) with a Camera2D (240px wide, 160px high) as a child node.
I want to instantiate many mobs at random positions within the world map but also I don't want them to spawn inside the Camera2D view rectangle (so the player can see enemies popping out form nowhere)
I have this code:
func _spawn_enemies(many: int) -> void:
for i in range(many):
var new_mob: = Mob.instance()
new_mob.global_position = _get_random_spawn_position()
func _get_random_spawn_position() -> Vector2:
var spawn_pos: = Vector2(
The spawing seems to work just right but sometimes a mob appears exactly on top of the player, killing it instantly.
Any suggestions? I thought of while loops and hard code dimensions but I think there just might be a better way.
Thank you very much for reading!!
var me: = "happy :)"