• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language GDScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Goal Oriented Action Planning example in Godot

Godot Goal Oriented Action Planning Example

Screenshot

This is the GOAP example implemented for this video. If you have any comments and suggestion that video's comments section may be the best place for them.

This is a personal experiment not tested in high load scenarios. The code is fully documented to explain the reasoning behind the implementation.

You can find a live demo here.

The main branch works on Godot 4. For Godot 3, check the godot_3 branch. Godot 3 is the version shown in the demo video.

What the example does

The main NPC (./scenes/satyr.tscn) needs to keep a firepit burning all the time.

This NPC has the following goals (higher numbers are higher priority):

  • Keep Fire Pit Burning (priority 1)
  • Keep Fed (priority 1 when hungry, 2 when very hungry)
  • Calm Down (priority 10): When afraid
  • Relax (priority 0): When there is nothing else to do

There is another NPC (not using goap), the Troll, which keeps wandering in the scene. If they get too close to the Satyr, they enter in a frightned state.

How it works

You can find all actions available at ./goap/actions/ and goals at ./goap/goals/.

The GoapAgent(./goap/agent.gd) class integrates the NPC with the planner. It is responsible by requesting plans and making sure the highest priority goal is being handled.

The GoapActionPlanner(./goap/action_planner.gd) is the heart of this implementation. When a plan is requested it first creates a graph with all valid paths. Then it walks the graph building plans (list of actions) while summing their costs. Finally, it returns the cheapest plan, which is executed by the agent.

In this implementation, I decided to have the action logic inside the action script. All actions have a perform method which receives an actor and a delta. Maybe I was biased by my Behavior Tree implementation, but I like the idea of actions being stateless and not including low level details.

Check the scripts for comments with contextual information.

Can I use this in my project?

I only own the code, assets are from analogstudios_.

Feel free to use this code as you see fit. Keep in mind this is an experiment and many edge cases are not being handled. Some are commented in the code, some others I might not have thought of. Also, I haven't tested it in stress situations.

There is no need for attribution. Anyway, in case you do something cool with it, let me know. I'd love to see it.

If you like this kind of content you might like my youtube channel or my Twitter.

More Repositories

1

godot-aseprite-wizard

Godot Editor plugin to help import Aseprite animations to AnimationPlayers, AnimatedSprites and SpriteFrames.
GDScript
836
star
2

godot-behavior-tree-example

Example of tree implemented in Godot, without extra plugins
GDScript
93
star
3

godot-clyde-dialogue

Clyde Dialogue Language Importer and interpreter for Godot.
GDScript
92
star
4

clyde-js

Dialogue language and tools for games.
TypeScript
62
star
5

godot-utility-ai

A simple utility AI example implemented in Godot
GDScript
34
star
6

react-responsive-mosaic

JavaScript
19
star
7

sse-client

EventSource implementation in Rust to handle streams of Server-Sent Events
Rust
17
star
8

godot-boids

Simple boids/flocking implementation in GDScript / Godot
GDScript
12
star
9

http-test-server

Programatically create resources and pre-defined responses for tests
Rust
10
star
10

godot-navigation-2d-example

GDScript
10
star
11

godot-hierarchical-task-network-example

Hierarchical Task Network example in Godot
GDScript
9
star
12

dotfiles

.dotfiles
Vim Script
6
star
13

video2gif

a dockerised helper for converting video to gif using ffmpeg and gifsicle.
Shell
6
star
14

godot-color-replacement-example

Here are 3 examples of how to replace color from parts of images (skin, hair, clothes) in Godot
GDScript
5
star
15

controlled-schedule

Recurring schedule for async tasks. Schedule next execution only after the current one finishes.
JavaScript
5
star
16

tmux-runner.vim

Interact with Tmux without leaving Vim
Vim Script
3
star
17

Codiad-Compass

Compass integration plugin for Codiad IDE
PHP
3
star
18

VagrantPHPEnvironment

My Vagrant PHP environment provisioned with Puppet
Puppet
2
star
19

vscode-clyde

Clyde dialogue syntax highlighting for VSCode
2
star
20

SassCompassDojo

Cรณdigo de exemplo sobre Sass / Compass
CSS
2
star
21

clyde

Clyde Dialogue Language
2
star
22

nchan-message-bus

Simple message bus using NCHAN
Dockerfile
1
star
23

godot-clyde-sample

Sample project for how to use Clyde Dialogue in Godot
GDScript
1
star
24

clyde.vim

Clyde dialogue language syntax file for VIM / NVIM
Vim Script
1
star
25

my-keep

A note-taking app inspired by Google Keep
JavaScript
1
star