OVERVIEW.md

Making a game bot challenging took more than giving it a state machine.

I wanted to make a game and find out how its bots actually worked. A finite state machine could tell an enemy when to patrol, chase, or attack; the harder question was how to make it demanding enough that the player had to stay alert without making every fight frustrating or impossible. Rebirth began with a sample map and a shooting system. From there, the game grew as I worked out both sides of a fight: what the player could do and how an opponent should respond.

Making combat more than a firing loop

Movement, a dash, knockback, and different guns gave the player ways to act, but enemies needed more than a straight chase to make those choices matter. Regular enemies gained patrol, pursuit, circling, short repositioning, dodging, attacks, and recovery. Five enemy types tune that shared controller with different weapons, ranges, speeds, and timings. The hard part was tuning those choices and timings: I wanted enemies that kept pressure on the player while leaving enough room to react. The seven player weapons also do different jobs, from sword reflection and shotgun spread to piercing magic and a rocket's burn effect. With only three inventory slots, picking up another weapon means giving one up.

Then the fights needed a shape beyond individual encounters. Entering a room closes its doors; waves spawn on valid floor tiles, and clearing them opens the route again. Treasure rooms change what the player can carry into the next fight. The Spirit King required a separate design: navigation, visible warnings before attacks, six special moves, and three phases as its health falls. A dialogue choice earlier in the prison escape changes the ending. The game became a route through escalating encounters rather than a collection of combat mechanics.

Gameplay showcase from the repository README. Playback starts muted; the complete browser game is linked above.Watch on YouTube

What came together in the playable game

The showcase above gives a quick view of those systems in motion. Rebirth is a playable browser game built in Unity and C#, with rooms, weapon decisions, distinct regular enemies, a boss fight, and an ending. The repository contains the scenes, prefabs, configurations, and scripts behind that experience. It was made with collaborators; the source and game are the team's work. For me, the project made game AI a design problem as well as a coding problem: the bot's behavior had to serve the pace and fairness of the whole game.

README.md

Rebirth

A 2D pixel-art action game about escaping a prison, fighting the Spirit King's forces, and choosing how the story ends. Move, dash, aim manually, trade weapons, clear enemy waves, and survive a multi-phase boss encounter.

At a glance

  • Combat: seven equipable weapons, manual mouse aim, recoil and knockback, projectile collision, and a shield-powered sword reflection.
  • Enemy movement: patrol, direct pursuit, orbital strafing, short unpredictable repositioning, and lateral dodges. Each archetype tunes the same controller with a ScriptableObject.
  • Progression: tilemap rooms close their doors on entry, spawn waves on available floor tiles, and reopen after the room is cleared. Treasure rooms offer more weapons.
  • Boss: the Spirit King follows a separate navigation and attack system, with telegraphed area attacks and three attack sequences selected by remaining HP.
  • Story: a Mystery Man encounter records a choice used by the ending flow.

Play and controls

Play the HTML5 build on itch.io. The controls below follow the checked-in player code and prefab:

InputAction
W A S DMove
MouseAim equipped weapon
Hold left mouse buttonFire or swing
Space or right mouse buttonDash
1 2 3 or RSelect an inventory slot / cycle weapons
EPick up a nearby weapon
GDrop the equipped weapon
FReflect projectiles while holding the sword and having shield; advance Mystery Man dialogue when active

The inventory has three slots. Picking up a fourth weapon drops the currently equipped one. Health and shield appear in the HUD; the third meter tracks dash availability (named mana in PlayerController). The published itch.io page has a slightly different control list, so use the game build's behavior if it differs from this checkout.

Arsenal

The seven player weapons are registered in ItemManager. Each pickup has an ItemSO, while its combat behavior and values come from a weapon prefab plus a RangeWeaponConfig or MeleeWeaponConfig asset. The values below are the player weapon config assets in this repository, not promises about a separately deployed build.

WeaponIdentityBase damageFire interval
SwordClose-range swing; F activates shield-consuming projectile reflection10Swing delay 0.3 s
PistolDeliberate single shots400.4 s
AKRapid fire250.2 s
ShotgunSpread pellets plus the inherited gun shot20 per projectile0.7 s
BowFast arrow projectile400.5 s
Magic OrbPiercing projectile (isMoveThroughObject)250.5 s
Rocket LauncherRocket impact and burn effect on enemies30 on impact1.0 s

Gun instantiates the configured bullet, applies fire timing and recoil for player-owned weapons, and marks the projectile with its owner tag. Bullet handles travel, hit detection, damage, knockback, impact effects, and lifetime. Shotgun/ShotgunBullet add spread; the rocket bullet adds a burn coroutine; Melee controls swing collision and reflection. Enemy-owned weapons use separate config assets under EnemyRangeWeaponConfig and EnemyMeleeWeaponConfig.

Enemies

Five regular-enemy prefabs share EnemyActionController, EnemyController, and EnemyWeaponAim. Their EnemyStatusConfig assets supply the weapon, engagement ranges, movement speeds, durations, and cooldowns.

Enemy prefabWeapon styleSight rangeAttack / chase rangeBase attack cooldown
Sword EnemyMelee pursuit165 / 53 s
Pistol EnemyMid-range gunfire1410 / 103 s
Shortgun EnemyClose-range spread168 / 85 s
AK EnemySustained gunfire1612 / 122 s
Bow EnemyLonger-range shots1814 / 145 s

These are serialized asset values. Actual attack and movement timing varies because the controller applies random cooldown and duration multipliers. EnemyController handles HP, hit flashes, burn damage, and a random close-guard visual variant.

How regular enemies move

This is the core of the regular-enemy AI. The controller chooses a state in Update, writes a velocity to Rigidbody2D, and applies a friction force. It does not use a NavMeshAgent; the boss does.

Idle / Patrol
    └─ player enters eyeRange, or enemy is hit → Chase
Chase
    ├─ player outside chaseRange → move directly toward player
    ├─ player inside chaseRange → Circle or Random reposition
    ├─ player inside dodgeRange, or enemy HP < 20 → Dodge
    └─ player inside attackRange and cooldown ready → attack, then Chase
Circle / Random ─ duration, destination, or stuck check → Chase
Dodge ─ dodge duration ends → Chase
  1. Patrol: choose one of four cardinal directions near the spawn point, walk to it, return to spawn, and wait a randomized patrol cooldown. eyeRange or a hit wakes the enemy.
  2. Pursuit: outside chaseRange, velocity points directly at the player. Inside it, the controller attempts its movement patterns instead of simply closing distance.
  3. Orbit (Circle): pick a radius and clockwise/counterclockwise direction, advance an angle around the player's position captured at the start of the move, then reverse direction for a second timed segment. This creates strafing around an encounter point; the orbit center is not continuously updated to the moving player.
  4. Random reposition (Random): choose a short offset, move toward it, and usually move partway back. Getting within 5 units of the player can end this pattern early and make circling available again.
  5. Dodge: when close enough and off cooldown, or below 20 HP, move at a random ±dodgeAngle from the player-facing direction for dodgeDuration. The default angle is 90°, producing a sideways evasive step.
  6. Attack and recovery: attack is allowed inside attackRange when its cooldown expires. The cooldown and movement durations are varied per enemy, and a short knockback lockout lets hits interrupt velocity changes. A periodic position check ends a pattern if the enemy appears stuck against a wall.

The enemy config exposes eyeRange, attackRange, and chaseRange separately, plus patrol/orbit/random/dodge speeds and timers. The asset author's intended tuning order is eyeRange > attackRange > chaseRange and chaseRange > circleRadius; the current archetype assets set attack and chase ranges equal. EnemyWeaponAim rotates the equipped weapon toward the player every 0.2 seconds after activation. Because this movement is velocity based, obstacles can still block an enemy; the wall check exits a stalled movement state rather than calculating a path around the obstacle.

Spirit King

The Spirit King prefab uses Spirit King.cs, a 2D-configured Unity NavMeshAgent, and a separate attack state machine. Its chase helper sets a destination toward the player and stops when it reaches the requested range. The boss has a telegraphed normal strike and six scripted skills:

AttackShowcase behavior
Normal attackWarning zone followed by a melee area strike
Skill 1Telegraph a direction, dash, and create an impact area
Skill 2Directional warning and laser line
Skill 3Dash and larger sword/area strike
Skill 4Mark ground positions and drop meteors
Skill 5Arena-scale warning and sweeping laser
Skill 6Mark valid floor positions and summon regular enemies

Attack sequences are defined by phase1, phase2, and phase3 arrays in the boss component. Code switches to phase 2 below 80% HP and phase 3 below 40% HP. Coroutines coordinate warning flashes, animations, damage windows, cooldowns, and camera shake. AreaAttack tracks players inside a telegraph, while BossAreaAttack applies repeated damage inside an active area.

Architecture guide

Runtime flow

flowchart LR
    Input[Player input] --> Movement[PlayerMovement]
    Input --> Inventory[ItemManager]
    Inventory --> Item[ItemSO + weapon prefab]
    Item --> GunMelee[Gun / Melee]
    GunMelee --> Bullet[Bullet / collision]
    Bullet --> Health[PlayerController / EnemyController / SpiritKing]
    Room[ActiveDoorArea] --> Map[MapManager / MapBossManager]
    Map --> Enemy[EnemyActionController]
    Map --> Boss[SpiritKing]
    Config[EnemyStatusConfig] --> Enemy
    Enemy --> GunMelee
    Boss --> Health
    Health --> HUD[HUD / BossHpBar]
AreaMain filesResponsibility
PlayerPlayerMovement, PlayerController, HUD_ControllerMovement/dash, damage and shield regeneration, UI updates through OnStatsChanged
InventoryItemManager, ItemSO, ItemPickableThree-slot inventory, pickup/drop/equip, item metadata
CombatWeapon, Bullet, ExplosionWeapon behavior, projectiles, hit effects, burn/fire areas
Regular enemiesEnemy, EnemyStatusConfigState-driven movement, aiming, health, data-driven tuning
RoomsMapManager, ActiveDoorArea, TreasureRoomDoor triggers, tilemap-based wave spawns, rewards
BossBoss, MapBossManagerNavigation, phases/skills, arena entry, boss HP and ending UI
NarrativeMysteryManDialogue and choice stored on PlayerController.ending

Room and combat lifecycle

  1. ActiveDoorArea detects the player entering a room, closes its door, and activates regular enemies or the boss.
  2. MapManager tracks placed enemies and spawned wave enemies. When the counts fall low enough, it picks random floor cells from groundTilemap excluding obstructionTilemap, then spawns the next wave. Once all configured waves and enemies are gone, it marks the room clear and reopens the door.
  3. TreasureRoom reacts to the cleared state and spawns its configured weapon rewards when the player approaches. ItemManager converts a pickup's ItemSO.itemName to the corresponding equipable prefab.
  4. A weapon instantiates a projectile or enables a melee collider. Collision routes damage and knockback to EnemyController, PlayerController, or SpiritKing. The HUD subscribes to the player's stat change event; the boss HP bar listens to boss HP changes.
  5. In the boss room, MapBossManager activates the boss and shows its HP bar. After the boss object is destroyed, it displays an ending panel based on PlayerController.ending, which the Mystery Man choice sets.

Adding content

New ranged weapon: create a RangeWeaponConfig with a bullet prefab, damage, fire interval, speed, recoil, and optional explosion; create a weapon prefab with Gun (or a subclass), gunPoint, animator, and ItemPickable referencing a new ItemSO. Register its name and prefab in ItemManager and its UI/inventory wiring. The current inventory uses a hard-coded name-to-prefab dictionary, so adding only an ItemSO is insufficient.

New regular enemy: create an EnemyStatusConfig that references the desired weapon prefab and melee/ranged config; create an enemy prefab with EnemyController, EnemyActionController, Rigidbody2D, animator, sprite, and weapon pivot. Add it to a room's MapManager.enemyPrefab list if it should appear in waves. Tune sight, attack, and chase ranges first, then orbit, random-move, dodge, and cooldown values.

New room or boss attack: room spawning needs ground and obstruction tilemaps, enemy prefabs, wave counts, placed-enemy references, door objects, and an ActiveDoorArea. Boss moves are coroutine-driven in Spirit King.cs; add the attack enum/coroutine, its telegraph and damage prefabs, and an entry in the desired phase arrays.

Repository map and setup

Assets/
  Scripts/             Player, weapons, bullets, enemy AI, boss, rooms, items
  ScriptableObjects/   Serialized weapon, enemy, and item configurations
  Prefabs/             Player, five regular enemies, boss, weapons, projectiles
  Scenes/              Main scene plus test/backup scenes
  Animations/          Character, weapon, projectile, and environment animations
  Images/              UI and weapon artwork
Packages/              Unity package manifest
ProjectSettings/       Unity project and build configuration
submodule/             NavMeshPlus checkout

Open the project with Unity 2022.3.51f1 (the version in ProjectVersion.txt). The enabled build scene is Assets/Scenes/TileMap1.unity. The project uses Universal Render Pipeline 14.0.11, Input System 1.11.2, Unity 2D/tilemaps, and NavMeshPlus for 2D navigation assets. If cloning from Git, initialize submodules (git submodule update --init --recursive) before opening Unity. The repository includes both submodule/NavMeshPlus and Assets/Submodule/NavMeshPlus references in .gitmodules; check their state if the editor reports missing navigation scripts. The scene/prefab setup and editor play mode have not been verified in this checkout; the published browser build is the quickest way to play.

Credits and license

Made by nightst and collaborators. The project includes third-party asset directories such as KrishnaPalacio, Warped Shooting Fx, and NavMeshPlus; consult their original license terms before reusing those assets. Repository source is accompanied by the MIT license.

Original code and documentation authored by Jakkarin Promsee are licensed under the MIT License. Third-party code, assets, datasets, and other materials are not covered by this license; their original terms apply.