Building Believable Enemy AI with Goal-Oriented Action Planning

Jul 13, 2024

Building Believable Enemy AI with Goal-Oriented Action Planning

Introduction

  • Believable enemy AI is challenging due to predictability.
  • Goal-Oriented Action Planning (GOP) offers advanced AI flexibility and complexity.
  • GOP was developed by Jeff Orin at MIT in the early 2000s.
  • Successfully implemented in games like F.E.A.R.

Key Concepts of GOP

  • Actions and goals are decoupled.
  • Agents analyze environment dynamically to devise plans.
  • Each action has preconditions, effects, and associated costs.
  • GOP operates in a goal-driven manner, reverse-engineering plans from desired goals.
  • Reduced overhead in extending AI capabilities.

Architecture Overview

  1. GOP Agent: Central component tying together beliefs, actions, and goals.
  2. Sensors: Provide environmental context to GOP.
  3. Planner: Uses algorithms to create plans.
  4. Plan Execution: Stack of actions executed towards the goal.

Beliefs

  • Foundational: Evaluate as true or false.
  • Examples: Last seen player location, food location.
  • Expose as public properties for dynamic evaluation.
  • Use a belief factory for simplified belief creation:
    • True/False beliefs
    • Location-based beliefs
    • Sensor beliefs

Actions

  • Described by name, cost, preconditions, and effects.
  • Actions wrap a strategy (e.g. idle, wander).
  • Strategy interface includes methods for start, update, stop.

Goals

  • Priority-based: Determines importance.
  • Describe desired world state after achievement.
  • Simple constructor and builder pattern for creation.

Planner

  • Utilizes beliefs, actions, and goals to create a plan.
  • Depth-first search: Builds graph nodes connecting actions to goals.
  • Nodes track parent, action, current beliefs, cost.
  • Filters goals based on priority and currently fulfilled effects.
  • Creates action plan as a stack and evaluates if plan is viable.

Implementation Steps

GOP Agent Setup

  1. Initialize Components: Sensors, static objects, nav mesh, animation controller.
  2. Define Beliefs: Dictionary setup with factory for ease.
  3. Define Actions: Use strategies like idle and wander.
  4. Define Goals: Chill out and wander as initial low-priority goals.

Strategy Implementation

  • Idle Strategy: Simple timer-based idle action.
  • Wander Strategy: Wanders within a set radius.

Additional Features

  • More complex beliefs (health, stamina, player-related).
  • More actions (move to food, eat, rest, chase, attack).
  • Goals with higher priorities (keep health up, seek and destroy).
  • Cost calculation for efficient pathfinding.

Testing and Debugging

  • Debugging: Use logs for action completion and plan evaluation.
  • Sensor setup: For player range detection and environmental interaction.

Advanced Considerations

  • Node-based editor for easy strategy planning.
  • Dependency injection for testing and scalability.
  • Algorithm enhancements: e.g., A* or D*- based planning.

Conclusion

  • Goal is to provide tools for creating advanced, believable AI behavior.
  • Encouragement to use third-party tools or adapt the solution provided.

Resources

  • Original Paper: Jeff Orin's GOP technique.
  • Assets: Node Canvas, utility libraries for sensors and timers.