
This article explores the systems architecture for rebuilding the classic game Missile Command using Unity’s Entity Component System (ECS). Here I describe the systems required to manage game entities and their interactions.
Key Systems
Missile Creation and Movement
The MissileSpawnSystem generates enemy missiles at randomized positions and directs them toward player buildings. In order to create a challenge in the game, we have to spawn the enemy missiles in randomized positions and move them directly toward the player’s buildings.
The MissileMovementSystem handles continuous missile movement along their designated direction vectors using delta time for frame-rate independence.
Defense Mechanics
Three systems manage player defenses:
- DefenseSpawnSystem - Spawns defenses at mouse-click positions when the player is ready
- DefenseGrowthSystem - Uses a simple sine wave to make the defense grow over time
- LifetimeCountdownSystem - Tracks defense duration and marks expired entities for deletion
Collision Detection
The MissileCollisionSystem handles three collision scenarios:
- Missile-defense collision (missile destroyed, player scores)
- Missile-building collision (missile destroyed, building takes damage)
- Missile below ground (missile destroyed)
Technical Approach
The systems use ECS scheduling patterns with Entities.ForEach() for efficient parallel processing. The collision system gathers building and defense entities into native arrays for collision checking against each missile.
Source Code
Full implementation available on my GitHub repository.