I’m making a “rougue-lite” game where the player will go on an elevator to go to the next floor and I want enemies to spawn in random places, the problem is I don’t know how to spawn enemies in a random place while also avoiding spawning too close to the center so they don’t spawn on top of and or overwhelm the player.
Does anybody have any ideas on an approach to this?
Create a square object to act as spawn area. Add 4 squares to fill the top, bottom, left, right areas where you want the enemies to spawn, leaving the center space empty.
Then add the below actions when you want to spawn the enemies:
- pick random object “area”
- create object “enemy” at position ___ ; ___ (fill the positions as below)
X position: area.X() + Random(area.Width())
Y position: area.Y() + Random(area.Height())
2 Likes