Broken Reality 2000 - AI Programming

Broken Reality 2000 - AI Programming

Flexible state machine and probability based reaction system for NPCs. Using context triggers, NPCs react dynamically to player actions: wandering, talking, or shifting into emotional states like anger or fear, bringing humor and life to Broken Reality's world.

Flexible state machine and probability based reaction system for NPCs. Using context triggers, NPCs react dynamically to player actions: wandering, talking, or shifting into emotional states like anger or fear, bringing humor and life to Broken Reality's world.

Category

Category

Unity · C# · AI Systems

Unity · C# · AI Systems

Role

Role

AI Programmer

AI Programmer

Studio

Studio

Dynamic Media Triad

Dynamic Media Triad

Duration

Duration

1 Year

1 Year

The Challenge

Design expressive NPCs that react differently to player behavior in a Y2K, humor-driven world. The AI had to feel dynamic and unpredictable without relying on complex behavior trees or heavy computation.

What I Built

Created a lightweight NPC AI system driven by contextual triggers and probability-based emotional reactions. Each NPC reacts differently to player actions, wandering, speaking, or shifting into states like scared or angry, using clean, reusable state logic tailored to the game’s surreal tone and comedic timing. The system remained performant and easy for the team to expand throughout development.

Technical Contributions

1. Probability-Based State Switching

Problem:
NPCs needed to react differently depending on what the player did, and reactions had to feel unpredictable but intentional.

Solution:
Created a probability-weighted selection system where each reaction has a defined chance range.

private void SelectStateRandomly(params (State, (int,int))[] states) 
{
    int rand = Random.Range(0, 100);
    for (int i = 0; i < states.Length; i++) {
        if (rand >= states[i].Item2.Item1 && rand <= states[i].Item2.Item2) {
            npc.SetState(states[i].Item1

Result:

NPCs respond with a variety of emotional states based on player interaction, making encounters feel reactive and unique.

2. Idle State Implementation

Problem:
NPCs needed natural ambient behavior when not interacting with the player.

Solution:
Programmed an IDLE_State that wanders on timers and triggers random dialog lines.

if (canMove) 
{
    randX = Random.Range(newPointRadiusMin, newPointRadiusMax);
    randZ = Random.Range(newPointRadiusMin, newPointRadiusMax);
    npc.Walk(new Vector3(randX, 0, randZ));
    canMove = false;
} else 
{
    timeToWait = Random.Range(walkWaitTimeMin, walkWaitTimeMax);
    if (time > elapsedTime) {
        elapsedTime = time + timeToWait;
        canMove = true;
    }
}

if (time > actionTime) 
{
    actionTime += talkRate;
    npc.Talk

Result:
NPCs feel alive and humorous through wandering and spontaneous dialog even without player involvement.

3. Modular State Logic

Problem:
Needed a clean way to organize all NPC reactions without hardcoding or clutter.

Solution:
Applied a project-specific version of the state machine pattern: each Broken Reality NPC holds its own state that manages behavior logic.

private void Update() {
    currentState.Update

Result:
Designers and programmers could easily add new emotional states or contextual reactions without rewriting core logic.

Results & Impact

  • Supported 10+ unique NPC behaviors using clean, reusable code

  • Achieved dynamic emotional reactions aligned with the game’s surreal humor

  • Delivered context-sensitive and unpredictable NPC behavior

  • Improved clarity and maintainability for team members working with AI logic

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