top of page
Game Download
Crusade AI Design/Development
In this project, I developed a robust, modular AI system within Unity, tailored for both single-player and multiplayer gameplay. Inspired by Souls-like combat design, this system enables dynamic, reactive enemy behavior while supporting complex boss encounters that feel challenging and rewarding.
Role
Lead Developer
team size
1 person
development time
6 months
Game Engine
Unity
Genre
Action Role-Play (Souls Like)
Technologies used

Unity

C#

GIT

Photoshop

Audacity

Trello
AI System in Action
​This demonstration showcases the AI system’s core features in a live gameplay environment, highlighting how AI characters seamlessly transition between states, adapt their combat behavior in real-time, and react dynamically to player actions. From idling and pursuing the player to engaging in complex boss encounters with health-based phase transitions, These clip illustrates the depth and flexibility of the AI system I designed and implemented.
State-driven behavior
The State Machine pattern allows AI characters to transition between discrete behaviors such as idle, chasing a target, or attacking. This design ensures modular, maintainable AI logic.
Each AIState, Idle, Pursue and CombatStance, is designed with a decoupled architecture, where each state implements a Tick() function that runs every frame. This modular approach ensures extensibility, making it easy to create complex AI behaviors by adding or modifying individual states without introducing dependencies. To maintain precise synchronization between the AI character’s root motion (handled via OnAnimatorMove) and Unity’s NavMesh navigation system, the AI’s local NavMesh transform is reset every frame:
Health-based phase transitions
Boss characters dynamically adapt their combat strategies as their health decreases, transitioning through multiple phases to create engaging, high-stakes encounters that challenge players to adjust their tactics.
Multiplayer synchronization
The AI system is designed to ensure consistent and responsive behavior across all connected clients in a multiplayer environment. By synchronizing AI movement, actions, and decision-making logic over the network, players experience seamless and predictable interactions, regardless of their connection status. This consistency is critical for maintaining fairness, immersion, and competitive balance, ensuring that AI-driven challenges remain engaging and reliable for every player in the session.
Technical Breakdown
This section provides a comprehensive technical breakdown of the AI Character System I developed for a networked multiplayer game in Unity. The system is designed to deliver engaging, responsive, and immersive enemy behaviors from patrolling and target detection to dynamic combat interactions with advanced mechanics like stance-breaking and strategic pivoting.
Built with a focus on modularity, scalability, and multiplayer synchronization, the AI system leverages Unity’s NavMesh for navigation, the State Design Pattern for behavior control, and Netcode for GameObjects for authoritative server-side logic in a multiplayer environment.
State transitions
The AI system is built around a state machine architecture, where each AI character transitions between distinct behavioral states such as Idle, PursueTarget, CombatStance, Attack, and specialized states like BossSleep. These transitions are handled using a SwitchState method, which resets any temporary state flags and moves the AI to the next logical state based on the current context and conditions. For example, the AI might switch from CombatStance to Attack when an appropriate attack is selected, or from PursueTarget to CombatStance when the AI reaches its target. Each state defines specific logic within its Tick method, ensuring that AI behavior remains modular, extensible, and easy to debug. This flexible state-driven system allows for complex AI behaviors, such as dynamically choosing attacks based on distance, angle, and probability, while enabling smooth transitions and maintaining separation of concerns between each state’s responsibilities.
Combat decision-making
The combat decision-making system enables AI characters to make dynamic and context-aware choices during encounters with players. the fundamental of system is the CombatStanceState, where the AI evaluates its current situation such as distance to the target, field of view, and attack viability before selecting an appropriate attack from a curated list. This decision process filters out unsuitable attacks by checking conditions like minimum and maximum distances, angle requirements, and the AI’s current state. The system also introduces a weighted random selection mechanism, where attacks have different probabilities of being chosen based on their assigned weights, ensuring varied and less predictable AI behavior. Additionally, the AI can make combo decisions, rolling for a chance to chain attacks together, which adds an extra layer of depth and realism to its combat patterns. By combining these checks with smooth transitions between attack, combo, and repositioning actions, the AI can adapt its strategy in real-time, creating more engaging and challenging encounters for players.
Combat Decision-Making Begins in CombatStanceState.Tick()
Attack Selection Logic – GetNewAttack()
Combo Decision Logic – AttackState.Tick()
Final Attack Execution – PerformAttack()
Health management and damage response
The health management and damage response system in this AI framework serves as a foundational mechanic that governs the AI’s ability to engage in combat, react to threats, and determine survival outcomes. By integrating health checks into the state machine, such as verifying if the AI’s current target is dead, the system ensures that AI behavior remains contextually accurate avoiding illogical actions like attacking defeated targets. The presence of an isDead flag within the AI’s combat data allows states like AttackState and CombatStanceState to gracefully exit combat and revert to an idle state when a target’s health reaches zero. While the damage-taking and health-reducing logic is likely encapsulated within an AICharacterManager or HealthComponent, the state machine references these flags to trigger appropriate transitions and behaviors. This modular approach allows for potential expansions like healing mechanics or damage mitigation effects. Additionally, the system enforces clean action flow by halting attack attempts if an AI character is already performing an action or if their health status dictates a change in behavior, contributing to robust and reactive AI combat systems.
Seamless pathfinding
Seamless pathfinding in the AICharacterManager is achieved through the integration of Unity’s NavMeshAgent, which allows AI characters to dynamically navigate the environment while remaining tightly synchronized with their behavior states and network logic. The system ensures smooth navigation by continuously updating the AI’s position and destination in the ProcessStateMachine() method. The AI’s agent calculates the distance to its current destination, adjusting its movement state based on proximity to the stopping distance. If the agent has a target and is moving, it dynamically calculates the direction vector to the target (targetsDirection), the viewing angle (viewableAngle), and the distance from the target (distanceFromTarget). These values are not only critical for pathfinding but also inform combat decision-making and state transitions. Additionally, the AI’s networked isMoving state is updated in real-time to ensure multiplayer consistency. The position and rotation of the NavMeshAgent are reset every tick to prevent drift or misalignment, which is especially important for characters with complex animations or those driven by root motion. This tight coupling of state logic, combat awareness, and real-time navigation allows AI characters to respond intelligently to their environment, seamlessly pursuing and engaging targets while respecting the game's spatial constraints.
Multiplayer synchronization
The AICharacterManager class is designed with robust multiplayer synchronization in mind, ensuring that AI characters behave consistently across all clients in a networked game. Using Unity’s Netcode framework, critical AI properties such as health (currentHealth) and movement state (isMoving) are synchronized across the network by leveraging network variables and event subscriptions. For example, the currentHealth variable is monitored through the OnValueChanged event, triggering the CheckHP method on the AI’s network manager to ensure all clients reflect the correct health state. Similarly, the AI’s movement status is updated in real-time within the ProcessStateMachine() method, setting isMoving.Value based on the NavMeshAgent’s current destination and stopping distance, ensuring consistent visual and gameplay feedback for all players. Furthermore, key components like the combat manager, locomotion manager, and inventory manager are instantiated and initialized on the network owner, guaranteeing that the AI’s state transitions, combat logic, and pathfinding align correctly in multiplayer sessions. This careful handling of networked variables, combined with event-driven updates and deterministic state machine processing, ensures that AI characters act as a unified, predictable force across clients, enabling fair and immersive multiplayer interactions.
Architecture Overview
AICharacterManager
The AICharacterManager serves as the central controller for all AI-related functionality, acting as the brain that orchestrates state-driven behavior, combat decisions, navigation, and network synchronization. This class extends a broader CharacterManager base, integrating multiple specialized managers such as AICharacterNetworkManager, AiCharacterCombarManager, AICharacterLocomotionManager, and AICharacterInventoryManager to handle networking, combat logic, movement, and equipment respectively. At its core, the AICharacterManager leverages a robust state machine system, where each AI state (such as IdleState, PursueTargetState, CombatStanceState, and AttackState) is instantiated upon network spawning, ensuring modular and flexible behavior. During each FixedUpdate tick, the ProcessStateMachine() method invokes the current state's logic through Tick(), allowing seamless transitions between states based on in-game context. The AI also continuously updates positional and targeting data, recalculating angles and distances to targets in real time, while synchronizing movement flags via network variables for multiplayer support. Pathfinding is handled through Unity’s NavMeshAgent, ensuring fluid navigation across complex terrain, with position and rotation alignment safeguards to prevent drift. Overall, AICharacterManager serves as a powerful, extensible framework for AI behaviors, integrating combat logic, navigation, and networking into a cohesive system that drives intelligent, lifelike AI characters.
Specialized components
The AICharacterManager system is architected with a clear separation of responsibilities through specialized components, ensuring modularity, scalability, and ease of maintenance. Each aspect of AI behavior such as combat logic, locomotion, inventory handling, and network synchronization is delegated to dedicated manager classes: AICharacterCombatManager, AICharacterLocomotionManager, AICharacterInventoryManager, and AICharacterNetworkManager. This design allows each subsystem to focus solely on its domain, such as combat systems handling attack decisions and damage responses, while locomotion manages movement and pathfinding. The AICharacterManager acts as the orchestrator, initializing these components during Awake() and wiring up critical events, like health change monitoring via OnValueChanged. This separation enables clean, modular development where individual managers can evolve independently, reducing coupling and improving maintainability. It also simplifies testing and debugging, as developers can isolate and validate each subsystem without impacting unrelated areas. By encapsulating functionality in specialized managers, the system promotes clear, reusable code architecture an essential foundation for complex, networked AI systems in modern game development.
Extensible design
The architecture of the AICharacterManager demonstrates a highly extensible design, enabling developers to expand and modify AI behavior without needing to overhaul core systems. By using the State pattern, AI behavior is modular and easy to extend: new AI states like IdleState, PursueTargetState, CombatStanceState, and AttackState are implemented as separate scriptable objects or classes, which can be easily swapped, cloned, or enhanced to create new behaviors. The core AICharacterManager handles state transitions generically, allowing for seamless addition of new states or transitions without modifying the underlying logic. Furthermore, the use of specialized manager components such as AICharacterCombatManager, AICharacterLocomotionManager, and AICharacterInventoryManager ensures that specific functionality is encapsulated, promoting easy integration of new features like advanced combat systems, custom locomotion behaviors, or complex inventory mechanics. By following the principles of encapsulation, separation of concerns, and composition over inheritance, this design empowers developers to iterate and innovate rapidly, supporting long-term scalability and adaptability as game requirements evolve. Whether adding new AI tactics, integrating multiplayer features, or introducing new combat mechanics, the system is prepared to grow—one modular component at a time.
Lifecycle & Multiplayer Integration
The Weapon System is seamlessly integrated with the AI framework, ensuring that enemy characters can wield, equip, and use weapons just like player characters in a synchronized multiplayer environment. This enables AI enemies to participate fully in combat encounters with appropriate weapons, attack patterns, and damage profiles, maintaining parity with player capabilities and creating a fair, engaging gameplay experience.
AI Weapon Equipping & Ownership
Weapons can be spawned dynamically through a centralized weapon spawner system, whether placed in the level or granted as part of a character's loadout.
Upon spawning, each weapon is assigned an authoritative owner (player or AI character), ensuring that all weapon interactions—such as equipping, attacking, or dealing damage—are correctly synchronized across the network.
The system uses Network IDs and authority checks to ensure that only the server or a designated authoritative client can make critical decisions, such as applying damage or triggering effects.
AI Attack Logic & Synchronization
All combat actions, including attack initiation, damage application, and critical hit checks (e.g., backstabs, ripostes), are processed on the server to maintain authoritative control. This prevents cheating or desync issues and ensures fairness in multiplayer gameplay.
The system implements a hit detection pipeline using raycasts, trigger volumes, or custom colliders, with server-validated results sent to all clients to trigger visual feedback (such as hit sparks, sound effects, and camera shakes).
AI Weapon Hit Detection
AI weapon attacks use the same hit detection pipeline as players, utilizing colliders, raycasts, or trigger volumes to validate hits against targets.
Hit events are broadcast to all clients, triggering appropriate visual and audio feedback (e.g.,blood effects, impact sounds).
Special interactions like stance breaking and critical attack windows (e.g., backstabs) are fully supported for AI enemies, ensuring they can participate in advanced combat mechanics.
Edge Case Handling
The system includes robust handling for AI weapon desyncs, network latency spikes, or AI disconnections (e.g., from server migration or host transfer), ensuring AI combat behavior remains stable and reliable during complex multiplayer sessions.
AI System
I engineered a robust and scalable AI system within Unity, utilizing a modular, state-driven architecture tailored for both single-player and multiplayer environments. Inspired by Souls-like combat design, the system enables dynamic, reactive enemy behavior and supports advanced boss encounters. Key features include health-based phase transitions, adaptive combat patterns, and seamless synchronization of AI behavior and movement across networked clients. The architecture is designed for extensibility, allowing developers to easily implement new enemy types, abilities, and state logic while maintaining clean code separation and multiplayer reliability
Below is a brief demonstration of the AI system in action, highlighting key features such as state-driven behavior and health-based phase transitions. This clip showcases the core functionality of the system I designed and implemented
The AICharacterManager serves as the central controller for all AI behavior and state management. Acting as the 'brain' of each AI entity, it orchestrates movement, combat decision-making, state transitions, and health management. It also integrates seamlessly with Unity’s NavMesh system for dynamic pathfinding and navigation. This manager ensures modular, maintainable AI behavior suitable for both standard enemies and complex boss encounters in networked gameplay environments."
The AICharacterManager functions as the core controller for AI characters in a networked multiplayer environment, acting as the central decision-making component responsible for coordinating all major AI subsystems. It manages transitions between states such as Idle, Pursue, and Attack using a modular state machine architecture. For movement, it integrates seamlessly with Unity’s NavMesh system to enable real-time pathfinding and terrain-aware navigation. In combat scenarios, it handles target detection, attack logic, and awareness of player positions. The system also ensures consistent AI behavior across networked clients by synchronizing relevant data through the AICharacterNetworkManager. As the root orchestrator, the AICharacterManager delegates tasks to specialized components for movement, combat, and animation, maintaining a clean and extensible architecture.
Architecture Overview
The AICharacterManager inherits from a base CharacterManager class, which provides shared character logic such as animation handling, stat management, and death behavior. It integrates multiple subsystem managers including combat, movement, inventory, and networking to clearly separate responsibilities and maintain clean architecture. Each AI character independently manages its own NavMeshAgent, enabling precise pathfinding and responsive navigation across complex terrain. Built using Unity’s component-based design philosophy, the system remains modular, extensible, and easy to test, allowing for efficient development and debugging.
AI Behavior Control
The AI system is built on a modular state machine architecture, where each behavior such as idling, pursuing a target, or attacking is encapsulated within its own state class (e.g., IdleState, PursueTargetState). These states are designed to be interchangeable, allowing each one to return a new state based on in-game conditions, enabling clean, dynamic, and responsive behavior transitions (e.g., from detecting a player to chasing and attacking). The core method, ProcessStateMachine(), is executed every FixedUpdate() cycle to continuously evaluate and update the AI’s behavior in real time, ensuring consistent and frame-accurate decision-making.
Main Lifecycle Hooks
The AICharacterManager leverages Unity's lifecycle methods to manage its behavior efficiently in both single-player and multiplayer contexts. During Awake(), it initializes and caches references to key components. The OnNetworkSpawn() method ensures that initialization logic is only executed on the owning instance, a critical consideration for maintaining authoritative control in a multiplayer environment. OnEnable() and OnDisable() handle the registration and deregistration of UI-related events, such as health bar updates, promoting clean resource management and optimal performance. The Update() loop is used for handling ongoing, frame-dependent tasks like action recovery and cooldown timers, while FixedUpdate() is responsible for running the AI state machine and syncing movement data, ensuring smooth animations and accurate networked behavior.
bottom of page