top of page

Operation Phantom AI Development

Operation Phantom is a stealth-action game inspired by the Hitman series. This solo project was designed to explore and implement core stealth mechanics, focusing on intelligent AI behaviors, player detection systems, and mission structures that challenge players to think strategically. My goal was to deepen my understanding of AI-driven gameplay while creating immersive and reactive enemy systems.

Role

Lead Developer

Game Engine

Unity

team size 

1 person

Genre

Action Role-Play (Souls Like)

Technologies used

image.png

Unity

image.png

C#

image.png

GIT

image.png

Photoshop

image.png

Audacity

image.png

Trello

Coding Process

1

Concept & Planning

2

Initial Prototyping

System Development

3

In developing Operation Phantom, I followed a five-step design process, which I will elaborate on throughout this portfolio piece. Each phase was crucial in shaping the game's mechanics, systems, and overall player experience.

Testing & Iteration

4

passover and feedback

5

AI Guard System

This code implements a patrolling guard AI with state-based behaviors walking, chasing, shooting, and dying built using Unity’s CharacterController for movement and raycasting for player interaction.

Core AI Behaviors Implemented

System

Waypoint Patrol

Player Detection

Chase & Combat

Health & Damage

Details

Guard follows a set of waypoints in a loop (forward/reverse). Smooth movement and rotation for natural patrols.

Vision-based detection using Physics.CheckSphere. Triggers alert states when the player is seen.

AI increases speed when chasing, stops to shoot at player using Raycast, respects cooldowns to prevent spam.

Guards take damage, enter alert mode, and die with animations when health reaches zero.

Systems in Detail:

AI State Machine

​Waypoint Patrol Logic

The AI guard patrols along a predefined set of waypoints, moving between them using linear interpolation via the CharacterController.Move method for smooth and controlled motion, while the rotation is handled through spherical linear interpolation (Slerp) for natural and fluid turning. Once the guard reaches the final waypoint in the sequence, the direction is reversed, creating a continuous patrol loop that maintains the guard’s presence throughout the level. While in the patrol state, the guard triggers a walking animation and plays footstep sounds, providing visual and auditory feedback that enhances the sense of realism in the environment.

in this image the Capsule are show as a repression of location that the ai uses as a waypoint system 

image.png

this video show the ai guard patrol system off. 

The AI patrols the environment by following a set of waypoints, using the currentWaypointIndex and movingForward flags to determine the patrol direction. When the AI reaches the end of the waypoint list, it reverses direction, creating a continuous and seamless patrol loop. To ensure smooth turning during patrols, the AI uses spherical linear interpolation (Slerp) for rotation, enhancing realism by mimicking natural movement.

Player Detection Logic

The AI system uses layer-based detection for flexibility, enabling specific filtering of objects like the player character within the environment. It differentiates behavior between chasing and shooting based on the player's distance, allowing for varied and responsive enemy interactions. The AI employs stateful logic using the isAlreted flag, which governs transitions between patrol, chase, and attack states, creating a layered and reactive system.

The AI employs sphere-based detection (via Physics.CheckSphere) to monitor the player’s presence within two critical radii: vision and shooting. When the player enters the vision radius but remains outside the shooting radius, the guard chases by calculating a normalized direction vector and moving towards the player. If the player enters the shooting radius, the guard stops moving, smoothly aims at the target using Quaternion.Slerp, and fires a raycast from a designated muzzle position (ShootingRaycastArea). Upon a successful hit, the guard applies damage to the player and spawns blood effects at the point of impact, enhancing visual feedback. A shooting cooldown is enforced using Invoke, ensuring the guard fires in controlled bursts rather than continuously.

Chasing Logic

When the player is detected within the guard’s vision radius but outside the shooting radius, the AI transitions to a chasing state. The guard calculates a normalized direction vector toward the player, multiplies it by its running speed, and moves using the CharacterController to maintain consistent physics behavior. Simultaneously, the guard smoothly rotates toward the player using Quaternion.Slerp for natural turning, and switches its animation state to running creating a dynamic and responsive chase that feels grounded and immersive.

The guard’s movement is driven by Unity’s CharacterController, ensuring consistent control across all AI states. The AI employs smooth rotation via Quaternion.Slerp, which allows it to fluidly turn toward its target, whether it’s a waypoint or the player. Animations are tightly integrated into the state machine walking during patrols, running when chasing, and shooting during combat enhancing immersion by visually matching AI behavior to its current state. This design creates a natural, believable movement system that bridges AI logic and player feedback.

Health System & Death Logic

Both AI guards and bosses utilize a health-based damage system that tracks incoming damage and triggers death upon reaching zero health. Once defeated, the AI transitions into a dead state, which includes playing specific death animations, disabling active components (like AI movement or NavMesh agents), and enabling DeadBodyPick functionality for interaction. This system ensures consistent combat feedback across different enemy types, blending gameplay logic with visual and interactive elements for a polished and cohesive experience.

The health system governs damage intake and death transitions across AI characters. Upon health reaching zero, the DeadBodyPick interaction system is activated, allowing players to interact with fallen enemies. The AI’s active behavior, such as patrol, chase, or shooting, is fully disabled after death to prevent unintended interactions or lingering behaviors. This design ensures a seamless blend between combat mechanics, visual feedback, and post-combat interaction, creating a more immersive and polished gameplay experience.

AI Architecture

To ensure robust, scalable, and maintainable AI behavior for Operation Phantom, I implemented a Finite State Machine (FSM) architecture. This approach allows the AI to react dynamically to player actions through clearly defined behavioral states, while keeping logic compartmentalized for easier debugging and feature expansion.

Each guard AI transitions between states based on player proximity, visibility, health, and internal cooldowns. This structure not only mirrors the design philosophy of stealth-action games like Hitman but also provides a strong foundation for future AI behavior types such as snipers, heavy guards, or civilians.

image.png

Each state includes its own behavior logic, animation triggers, and audio cues. Transitions are driven by the following conditions:

State

Patrol → Chase

Chase → Attack

Attack → Chase

Data-Driven UI

Details

Player enters vision radius

Player enters shooting radius

Player exits shooting radius

AI health reaches 0

State changes are driven by internal flags, radii checks, and cooldown timers, including:

  • isAlerted: Set when the player is first detected; allows transition out of patrol.

  • playerInVisionRadius: True if the player is within sight range (sphere check).

  • playerInShootingRadius: True if the player is within attack range.

  • health <= 0: Triggers transition to Death.

  • previouslyShoot: Temporarily disables shooting to enforce fire-rate cooldown.

Scripted Architecture

Script Name

AIGuardManager.cs

Function

Main controller. Stores current state, handles transitions, and manages animations.

PatrolState.cs

ChaseState.cs

AttackState.cs

DeathState.cs

Contains logic for waypoint movement, rotation, and idle animations.

Manages target pursuit using directional movement and speed adjustment.

Handles raycast targeting, aim rotation, cooldowns, and damage application.

Triggers once health hits zero; disables all other states and logic.

This modular approach makes it easy to add new states like Search, Idle, or Call Backup, or to create new enemy types with behavior variations.

​Expandability and Future Additions

The current FSM system is designed with extensibility in mind. Possible future additions include:

  • Search State: When a guard loses sight of the player, enter a search pattern or investigate the last known location.

  • Communication System: Guards can alert nearby allies using a shared alert manager or broadcast system.

  • Suspicion Meter: Introduce a graded alertness system (inspired by Metal Gear Solid), allowing partial detection and sneaking past guards.

  • ScriptableObject Integration: Move detection radii, speeds, and behaviors into ScriptableObjects for modular tweaking without modifying code.

Code Challenges and Solutions

Managing Alert Transitions

Managing Alert Transitions was a core challenge during development, as it was essential for guards to smoothly transition between their patrol, chase, and shooting states based on the player’s proximity and level of alertness. Initially, guards would behave unpredictably, sometimes skipping states or getting stuck. To resolve this, I implemented a system of boolean flags such as isAlerted, playerInVisionRadius, and playerInShootingRadius which tracked the player’s position relative to the guard’s detection zones. These flags controlled the guard’s behavior transitions in a logical and predictable manner, ensuring that guards responded appropriately to player actions: patrolling normally, becoming alerted when the player entered their vision radius, and engaging in combat when the player moved within shooting range. This solution provided a clear and scalable system for managing guard state changes.

Preventing Rapid Shooting

Another key challenge was avoiding excessive shooting behavior when the player was within the guard’s shooting range. Without proper control, guards would rapidly fire in quick succession, overwhelming the player and breaking the intended combat flow. To address this, I introduced a cooldown system by implementing a previouslyShoot boolean flag, which temporarily disabled shooting after each shot. This flag was reset using Invoke, allowing a brief delay between shots and ensuring a more balanced combat experience. This approach not only prevented guards from spamming attacks but also introduced a natural pacing to their shooting behavior, creating opportunities for the player to react or escape.

  • Facebook
  • Twitter
  • LinkedIn

©2021 by Joseph Merrick. Proudly created with Wix.com

bottom of page