This project implements a Goal-Oriented Action Planning (GOAP) system for NPC AI in games. The system allows NPCs to plan and execute sequences of actions to achieve their goals based on the current world state.
The system consists of several key components:
- Action: Represents a single action that an NPC can perform, with preconditions and effects
- Planner: Finds a sequence of actions to achieve a given goal
- VisionSensor: Simulates the NPC's perception of the environment
- World State: Tracks the current state of the game world
The system follows a typical GOAP architecture:
-
The NPC has a set of possible actions, each with:
- Preconditions (what must be true to perform the action)
- Effects (how the action changes the world state)
- Expected effects (potential outcomes)
- Cost (how "expensive" the action is)
-
The planner:
- Takes a goal (desired world state)
- Searches for a sequence of actions that can achieve the goal
- Considers action costs to find efficient plans
-
The vision sensor:
- Updates the world state based on what the NPC can perceive
- Simulates detection of enemies and provisions
graph TD
A[Start] --> B[Update World State]
B --> C[Get Next Goal]
C --> D[Plan Actions]
D --> E{Can Achieve Goal?}
E -->|Yes| F[Execute Action]
E -->|No| G[Find New Goal]
F --> B
G --> C
subgraph World State
H[Enemy Detection]
I[Food Detection]
J[NPC Actions]
end
subgraph Planning
K[Check Preconditions]
L[Evaluate Effects]
M[Calculate Costs]
end
B --> H
B --> I
F --> J
D --> K
D --> L
D --> M
The system is designed to be integrated into a game engine. The main loop:
- Updates the world state based on sensor input
- Determines the next goal
- Plans a sequence of actions to achieve the goal
- Executes the planned actions
The system includes several example actions:
- Basic movement (Idle, Walk, Run, Jump)
- Combat (Attack)
- Survival (Eat)
- Navigation (searching for enemies and provisions)
- .NET Core
- No external dependencies required