top of page

GOAP Guard AI

falmouth logo.jpg

Unity (C#) | GOAP Planning | NPC AI | Editor Tools
 

This project demonstrates a GOAP (Goal-Oriented Action Planning) AI system designed for NPC guard behaviour in Unity. Agents plan actions based on world states, goals, and available actions, allowing them to dynamically adapt their behaviour in response to the environment.

The project also includes custom editor tools to simplify configuration of actions, patrol routes, and guard behaviours.

​

​​​

​

​

​

​

​

guard AI pic for page.PNG

Editor tools:

I decided to create editor tools mainly for user experience such as ease of use to edit the system to their liking.

Patrolling Editor

Here is a patrolling waypoint manager that can be created for any guard with a click of a button. The patrol points can be built with a button press and all the developer needs to do is move them where the patrol path needs to be.

waypoint builder.PNG
waypointsPNG.PNG
guardwaypointManager.PNG

Guard ai manager Editor

After creating the simple GUI implementation on patrol points I decided to build an AI manager editor window for users to easily create new guards and customise them to their liking. This is mainly using scriptable objects and changing data through an editor window. When the user creates a new guard with the button it creates a new scriptable object asset with all the details filled in.

​

AImanagereditor.PNG
create new guard editor window.PNG

This is the window that gets opened up after clicking the "Create new guard" button, this is where the users can customise their guard and save it's data.

goap guard AI editor manager.png

Goal orientated action planning(GOAP)

The AI uses a Goal-Oriented Action Planning architecture inspired by STRIPS-like planning systems. Agents evaluate world states, action preconditions, and effects to construct a sequence of actions that satisfies their current goal.

​

This allows guards to dynamically select behaviours such as patrolling, investigating, or engaging threats depending on the game state.

​

Here is a screenshot of the current world states that are given to the planner:

updated world states.PNG

Here are the current pre-conditions and effects for the patrolling action:

preconditions and effects patrolling.PNG

Here is some code from a patrolling action class that runs a simple patrolling system around points using the way-point manager that can be created from the patrolling action editor button shown above previously:

patrolling.PNG

Current goals that are given to the AI: "guardArea", and "survive":

​

goals.PNG
Debugging the Planner

 

Debugging the GOAP planner was initially difficult because it was hard to visualise which actions were being selected during planning. To address this, I implemented debugging tools that display the current action queue and threat level in real time.

This made it easier to inspect the AI’s decision-making process and identify issues with planning behaviour.

I also created a simple UI debug system that shows the agent’s current action and threat state during gameplay.

guard goal.PNG
guard UI.PNG
AI System Components

This project was designed as a reusable AI guard system for NPC characters. The system includes a range of behaviours and world states that allow agents to dynamically plan actions using GOAP.

The AI evaluates available actions, current world states, and active goals to determine the most appropriate behaviour at runtime.

milanote guard.PNG
References:


Orkin, J., n.d. Goal-Oriented Action Planning (GOAP). [online] Alumni.media.mit.edu. Available at: <https://alumni.media.mit.edu/~jorkin/goap.html> [Accessed 7 December 2021].

  • LinkedIn

©2021 by Ethan Jones. Proudly created with Wix.com

bottom of page