AI Sandbox

This post is a draft and may undergo changes over time.

I am sometimes working on an AI sandbox game with Unity. I implement various AI techniques I found in books, using Unity as a basic game framework and without using its advanced features.

I implement AI features in C# from AI Game Engine Programming (code samples in C++) and Artificial Intelligence for Games (pseudocode). Because of the specific features of C# and Unity, I adapt the code as needed while trying to keep the same behavior as described in the books. Sometimes, I am not satisfied with a specific behavior so I have to change the code further.

My project is uses a Git submodule to gather AI scripts that are reusable between games. The submodule repository is available publicly on Bitbucket as Unity Commons – AI (branch feature/movement). Note that it is a work in progress, but you can read the code to compare your implementation of the AI techniques with mine.


Finite-State Machine

Source: AI Game Engine Programming

Unity implemented Finite-State Machines (FSM) for its Animator, but I recreated my own system for training purpose. It heavily uses generic and is entirely code-based. Currently, it doesn’t support data-driven state programming. For an FSM system that supports transition injection, check out libraries like solid-state (made by another developer).

[add video guard changing state]


Source: Artificial Intelligence for Games

I have implemented pseudo-code from the book until Chapter 3.4.2. I have implemented a variety of Steering Movements, which you can see in action below.

[add videos]

I have also implemented some basic ballistic from Chapter 3.5?: Physics Prediction.

Comments are closed.