RTS: AI & Gameplay Systems

RTS: AI & Gameplay Systems

A solo developed real-time strategy game built in Unity featuring a custom behavior tree AI, modular unit systems, grid-based building mechanics, and full RTS player controls.

A solo developed real-time strategy game built in Unity featuring a custom behavior tree AI, modular unit systems, grid-based building mechanics, and full RTS player controls.

Category

Category

Unity · C# · AI Systems · Game Systems

Unity · C# · AI Systems · Game Systems

Role

Role

Game Programmer

Game Programmer

Studio

Studio

Solo Project

Solo Project

Duration

Duration

6 Months

6 Months

The Challenge

Develop a real-time strategy game with intelligent enemy AI, building systems, and complex unit management. The AI needed to prioritize resources, defense, and offense across a multi-layer decision system while maintaining 60+ FPS performance with hundreds of active agents, real-time combat, and live player commands.

What I Built

I engineered the full RTS gameplay: a 6-layer behavior tree AI for strategic decision-making, a modular unit architecture using the state pattern, responsive player controls with drag-select and context-sensitive commands, adaptive enemy logic balancing resources and combat, and the complete RTS loop including building systems, NavMesh pathfinding, UI integration, and real-time unit production.

Watch it in action

Technical Contributions

1. Multi-Layer Behavior Tree Architecture with Strategic AI

Problem:

Build an enemy AI capable of managing defense, economy, production, and unit allocation simultaneously without decision conflicts, while adapting to player behavior.

Solution:

Implemented a 6-layer hierarchical behavior tree with 20+ node types handling everything from global strategy to individual unit actions.

public class EnemyAI : MonoBehaviour 
{
    private BehaviorTree tree;
    private SequenceNode root = new SequenceNode();

    private void InitBehaviorTree() 
    {
        tree = new BehaviorTree(root);

        var underAttack = new CheckIfUnderAttackNode(tree);
        var checkSpaces = new CheckUnitSpacesNode(tree);
        var checkRecolectors = new CheckRecolectionUnitsNode(tree);

        tree.AddNode(root, underAttack);
        tree.AddNode(underAttack, checkSpaces);
        tree.AddNode(checkSpaces, checkRecolectors);
        // ... continues through 6 full layers
    }

    private void Update() 
    {
        tree.Update

Result:

AI manages 15+ collectors, 700+ walls, and multiple factories while reacting dynamically to pressure, resources, and player attacks.

2. Advanced State Pattern for Unit Behaviors

Problem:

Support many unit types (mobile and stationary) with complex behaviors that switch states cleanly while scaling past 100+ active units.

Solution:

Built an inheritance-friendly state pattern, with shared abstract classes and clean state transitions including NavMesh actions.

public abstract class State 
{
    public virtual void OnStateEnter() {}
    public virtual void OnStateExit() {}
    public abstract void Update

public abstract class MobileUnit : Unit 
{
    protected State current;

    public void SetState(State next) 
    {
        current?.OnStateExit();
        current = next;
        current?.OnStateEnter();
    }

    protected override void Update() 
    {
        base.Update();
        current?.Update

Result:

Reduced code duplication by 70%, enabling new unit types with minimal overhead and fully modular behaviors.

3. RTS Player Control System

Problem:

Implement intuitive RTS controls: drag-selection, multi-select, and context-sensitive commands that react differently depending on target type.

Solution:

Built a full interaction stack with click filtering, selection box logic, and smart command interpretation (move, gather, attack).

if (Input.GetMouseButtonDown(1)) 
{
    foreach (var obj in Player.Instance.GetSelectedUnits()) 
    {
        var unit = obj.GetComponent<MobileUnit>();

        if (hit.collider.CompareTag("Resource")) 
        {
            var intern = unit.GetComponent<Intern>();
            intern.SetState(new GoingToFarm_State(intern, hit.collider.GetComponent<StationaryResource>()));
        }
        else if (hit.collider.CompareTag("EnemyUnit")) 
        {
            unit.SetState(new ApproachingEnemy_State(unit, hit.collider.GetComponent<Unit>()));
        }
        else 
        {
            unit.SetState(new Walking_State(unit, hit.point

Result:

Supports single-select, multi-select, drag-box, and smart right-click actions that automatically infer user intent.

4. Building System with Grid-Based Placement

Problem:

Allow players to place buildings with real-time feedback, grid snapping, rotation controls, and NavMesh-safe placement.

Solution:

Implemented a live preview system with grid snapping, rotation, and click-to-confirm placement.

if (Physics.Raycast(ray, out hit)) 
{
    var y = placeableObj.transform.position.y;
    placeableObj.transform.position = Grid.Instance.GetGridPoint(hit.point);
    placeableObj.transform.position =
        new Vector3(placeableObj.transform.position.x, y, placeableObj.transform.position.z);

    if (Input.GetKeyDown(KeyCode.R)) 
    {
        placeableObj.transform.Rotate(0, 90, 0

Result:

Grid-snapped, responsive building with real-time rotation and safe pathfinding integration.

5. Modular Behavior Tree Framework

Problem:

Needed a flexible, reusable AI framework to support multiple node types without rewriting core logic.

Solution:

Created a full Behavior Tree framework with abstract Node classes, Condition/Action/Decorator types, and parent–child relationships.

public class BehaviorTree 
{
    private Node root;

    public BehaviorTree(Node root) 
    { 
      this.root = root; 
    }
  
    public void Update() 
    { 
      root.Update(); 
    }
  
    public void AddNode(Node parent, Node child) 
    {
        child.SetFather(parent

public abstract class Node 
{
    protected List<Node> children = new List<Node>();
    public abstract void Update();
    public void SetFather(Node parent) 
    {
        parent.children.Add(this

Result:

Easily extended with new node types and logic branches, powering the RTS’s full strategic AI system.

Results & Impact

  • 6-layer behavior tree making 20+ strategic decisions per frame.

  • Architecture supporting unlimited unit types with ~70% code reuse.

  • Stable 60+ FPS with 100+ active units and complex real-time AI.

  • Cross-system coordination (AI, units, buildings, controls) achieved through modular patterns.

  • Clean architecture with proper inheritance, disciplined singletons, and separation of concerns.

Create a free website with Framer, the website builder loved by startups, designers and agencies.