JarkkoPar / Utility_AI_GDExtension

This repository contains the binaries and example project for the Utility AI GDExtension.
MIT License
76 stars 2 forks source link

Utility_AI_GDExtension

Utility AI | Behaviour Tree with Utility support | State Tree with Utility support | Node Query System

This repository contains the binaries and example project for the Utility AI GDExtension for Godot Engine.

The extension contains

Together these nodes can be used to create versatile AI to your games.

If you don't know what Utility AI is, here is what Wikipedia says about it:

"...Utility AI, is a simple but effective way to model behaviours for non-player characters. Using numbers, formulas and scores to rate the relative benefit of possible actions, one can assign utilities to each action. A behaviour can then be selected based on which one scores the highest 'utility'... - Wikipedia - Utility system

If you want the source code, you can find it here: Utility AI Source Code repository.

Features

Compatibility

Works on Godot 4.1.2 or newer versions. Currently 64 bit Windows, 64 bit Linux versions are available.

There are also experimental builds available for wasm32/web and MacOS (unsigned).

Installation

Just copy the addons-folder with all its contents to your Godot project root folder.

Documentation

You can find the documentation here.

Getting started and tutorials

Read the getting started tutorials here.

Authors

JarkkoPar with Contributors. Big thank you to all of you who've helped out!

Example project

The example project contains example scenes that show how to use the various nodes. With these examples you get to know the nodes of the Utility AI GDExtension:

Agent behaviour nodes

There are also specialized sensor nodes for adding vision to the AI agents, handling ranges, booleans, for instance.

Utility enabled Behaviour Tree nodes

The UtilityAI Behaviour Tree nodes can be used independelty as a regular behaviour tree. However, they have been designed to work with Utility based Considerations and the Node Query System, which allows for more complex behaviour for your AI agents. The available nodes are:

Utility enabled State Tree nodes

The UtilityAI State Tree nodes can be used independently as a regular state tree. However, similarly to the Behaviour Tree nodes, they have been designed to work with Utility based Considerations. The available nodes are:

Node Query System nodes

The UtilityAI Node Query System is used to perform utility based queries to find Top N nodes that fit the set criteria. It as two types of nodes: Search Spaces and Search Criteria. A NodeQuerySystem-singleton can be used to set a per physics frame time budget for all the queries and to control the CPU-time of all the queries.

A Search Space defines a set of nodes you will use in your query:

A Search Criterion filters and scores the nodes in a search space to find the top N nodes:

Example 1 - A dude following the mouse cursor

The first example is a simple one, where one AI controlled entity follows the mouse cursor. When it gets close enough to the cursor, it stops and waits. It is a gentle introduction to Utility AI.

Example 1
Example 1 - A dude following the mouse cursor

Example 2 - Dudes in combat

The second example provides a more elaborate example with several behaviours and behaviour groups for the AI agent with a multitude of sensors. In this example a blue and a red team of dudes pick up weapons and battle it out until only one team remains standing.

Example 2
Example 2 - Dudes in combat

Example 3 - Making (better) use of Actions

The third example shows a better, more re-usable way of using actions. In the earlier two examples the actions have been used only as an ID for an action. In this example the actions are extended with a script to contain the methods start_action(), execute_action() and end_action(). As a result the action node itself can be used perform what ever an action does, which both simplifies the AI Entity code and makes each action easier to share between different AI entities. Example 3
Example 3 - Making use of Actions

Example 4 - Adding perception

The fourth example shows how to add vision and hearing sensors to an AI agent, this time a Baddie. It uses a specialized sensor, UtilityAIArea2DVisibilitySensor, to achieve this. In the example a Baddie will chase you, the player, and investigate if you make too much noise. Example 4
Example 4 - Adding perception

Example 5 - Behaviour Tree with Utility

The fifth example is a 2D example that shows how to use the Utility enabled Behaviour Trees together with the Node Query System. Example 5
Example 5 - Behaviour Tree with Utility

Example 6 - Hide and seek

The sixth example is a 3D example that shows how to use the Node Query System to find a cover point to hide from the player. It uses the NodeQuerySystem-singleton to manage time budget of the queries and an Area3D Search Space with a set of criteria to find the best places for the AI to hide from you. Utility AI Agent behaviours are used to select the main behaviour and one of these behaviours uses a Behaviour Tree to handle the how the behaviour is realized and how errors are handled. Example 6
Example 6 - Hide and seek