⚠️ This framework is deprecated!
Goal v1.5.0 | GOAP AI for Roblox NPCs
📁 GitHub | 📦 Wally | 📚 API Docs | 📝 Changelog
A GOAP (Goal-Oriented Action Planning) library for building adaptive NPC behavior in Roblox. Instead of scripting exact behavior sequences, you define what NPCs can do and what they want - they figure out how to achieve their goals on their own.
"After searching for a proper GOAP implementation for Roblox and finding nothing, I built one myself."
Currently used in production for combat AI, survival systems, and squad tactics.
The Problem
Traditional NPC AI with behavior trees or conditional chains:
- Requires manual rewiring for every new behavior
- Edge cases multiply exponentially
- Results in predictable, scripted-feeling NPCs
- Becomes increasingly difficult to maintain
The Solution
GOAP works differently. You define:
- Available actions (what NPCs can do)
- Goals (what NPCs want to achieve)
- World state (current situation)
The planner automatically finds the optimal sequence of actions to achieve the goal.
| Behavior Trees | GOAP |
|---|---|
| Manually define all transitions | AI generates action sequences |
| New behavior breaks existing logic | Add actions without touching existing code |
| Rigid, predetermined responses | Dynamic adaptation to situations |
| "If hungry AND near food AND not in combat..." | "Goal: not hungry. Action available: eat food" |
Benefits
- NPCs adapt to situations dynamically
- Add new behaviors without breaking existing ones
- Emergent behavior from simple rules
- Less code to maintain
- Handles hundreds of NPCs efficiently
Example
local Goal = require(path.to.Goal)
local planner = Goal.Planner.new()
-- Define available actions
local gatherWood = Goal.Action.new({
name = "GatherWood",
cost = 2,
preconditions = {},
effects = { hasWood = true },
})
local makeFire = Goal.Action.new({
name = "MakeFire",
cost = 1,
preconditions = { hasWood = true },
effects = { hasFire = true },
})
planner:registerActions({ gatherWood, makeFire })
-- Define objective
local warmthGoal = Goal.Goal.new({
name = "GetWarm",
desiredState = { hasFire = true },
priority = 1,
})
-- Generate plan
local plan = planner:plan(worldState, warmthGoal)
-- Returns: GatherWood → MakeFire
The NPC doesn't have "gather wood then make fire" hardcoded. It discovers this sequence by understanding that making fire requires wood, which it can get by gathering.
Use Cases
Combat AI - Tactical enemies that flank when outnumbered, retreat at low health, call for backup, and use cover
Stealth Systems - Guards that patrol routes, investigate sounds, alert nearby units, and remember player positions
Town NPCs - Characters with daily routines that adapt based on needs (hunger, fatigue, work schedules)
Squad Coordination - Teams that avoid duplicate targeting, provide covering fire, revive allies, and coordinate flanking
Boss AI - Multi-phase encounters that adapt tactics based on health, summon reinforcements, and reposition strategically
Survival NPCs - Characters that prioritize competing needs (hunger, thirst, warmth, safety) and plan multi-step solutions
Installation
Via Wally
[dependencies]
goal = "aliboily/goal@1.5.0"
Then: wally install
Via GitHub
Download from releases and place in ReplicatedStorage.Packages.Goal
Quick Start
local Goal = require(ReplicatedStorage.Packages.goal)
local planner = Goal.Planner.new()
-- Define what the NPC can do
local patrol = Goal.Action.new({
name = "Patrol",
cost = 1,
preconditions = { alert = false },
effects = { patrolling = true },
})
-- Define what the NPC wants
local defendArea = Goal.Goal.new({
name = "DefendArea",
desiredState = { areaSecure = true },
priority = 5,
})
-- Generate and execute plan
local worldState = { alert = false, enemySpotted = false }
local plan = planner:plan(worldState, defendArea)
if plan then
for _, action in ipairs(plan) do
action:execute()
end
end
See main_example.server.lua for a complete implementation with 800 NPCs.
Features
- GOAP Planner - A* pathfinding, dynamic cost calculation, plan caching, interrupt handling
- Navigation - Grid pathfinding, cover evaluation, flanking routes, high ground calculation, escape paths
- Perception - Vision cones, hearing radius, awareness states, memory integration
- Personality Traits - 8 configurable traits (aggression, caution, etc.), 8 preset profiles, mood system
- Utility System - 10 evaluation curves, multi-factor decision making
- Memory - Short-term, episodic, and long-term memory with pattern recognition
- Shared Knowledge - Blackboard system for squad coordination and target management
- Parallel Processing - Actor-based execution, tick budgeting, frame distribution
- Production Features - Cooldown system, resource costs, state persistence, debug logging
Performance
- Handles 800+ concurrent NPCs
- Configurable frame budget (default 4ms)
- Object pooling for memory efficiency
- Parallel execution support
- Spatial grid for fast proximity queries
Contributing
This is an open-source project. Bug reports, feature requests, and pull requests are welcome on GitHub.
License
MIT - Free for commercial and personal use.