Enemies, spawning and difficulty
Putting things in the player's way, and making it harder the longer they last.
8 min readPlace a few, spawn the rest
Enemies you place in the editor are good for authored levels, where the same thing should happen every time. For anything endless you want a spawner: an invisible entity whose behaviour creates enemies as the game runs.
- waveSpawner — sends formations in sequence. Each wave names a texture, a count, a shape (line, vee, sine) and how long before the next.
- hazardSpawner — a steady stream of obstacles, weighted so some appear more often than others.
- depthSpawner — the 2.5D version, placing things ahead of the camera and clearing them once passed.
Making them dangerous
Two ways, and they are not the same:
- damageOnTouch on the enemy. It has an invulnerability window, which matters — an overlap fires every frame you are touching, so without one a single contact drains every life you have in a third of a second.
- An On Overlap rule in the graph, when you want something more than damage: a pickup, a door, a checkpoint.
Making them killable
Wire an On Overlap between your bullet tag and your enemy tag, then destroy both, add to the score and burst some particles. That is the whole loop, and it is four nodes:
On Overlap (bullet, enemy)
└─ Destroy (self) the bullet
└─ Destroy (other) the enemy
└─ Add To Variable score + 100
└─ Particle Burst
Difficulty that rises
A game at a constant difficulty stops being interesting in about ninety seconds. The kits ramp in one of three ways:
| Approach | How |
|---|---|
| Speed | A speed variable that climbs, read by the scrolling and the spawners. |
| Frequency | The gap between spawns shrinks with distance travelled. |
| Variety | Later waves introduce tougher enemies rather than more of the same. |
The simplest version is an On Timer node adding a little to a speed variable every few seconds, with everything else reading that variable. One number, and the whole game tightens.
Clean up after yourself
Anything spawned must eventually be destroyed, or the scene fills with things you cannot see. destroyOffscreen handles the usual case. Bullets should also expire on a timer, in case they never reach an edge.