Ever wondered how do they spawn enemies in games, in such a way that the spawn positions make sense and are somehow unpredictable?
“Simple”, you might say, “just use random numbers”. Well, this kinda works, at least most of the times. The problem lies within that 1% of times when you happen to spawn a monster on top of another or at a position that doesn’t make any sense. Depending on the game specifics there might also be other problems, like spawning large groups too close together, leaving most of the screen empty, spawning off-screen et cetera.
Here is our solution to the problem. We call it the “Awareness Sensor”. It is a module that examines the play-field and regularly fills a queue with spawn point suggestions. In the picture to the right you can see:
- on-screen spawn positions (blue)
- off-screen (white)
- off-playfield (black)
- possible horizontal and vertical line spawn positions (purple)
- already occupied positions (red) and
- neighbouring to occupied (green) positions
To ameliorate the fact that this is a regular grid, we add a random displacement within the boundaries of the cell.
Even though this grid approach is trivial in theory, making it run fast was rather complicated. We’re not going to bore you with the details. Just note that not all possible positions are displayed. The sensor is only working when more spawn positions are required, being gentle to your mobile’s battery so you can play more!
Stay tuned for more news and behind the scenes stuff!