Unity: How to Create a Learning AI

If you’re interested in creating AI elements to use in your video game, there are a few different approaches to take. We wanted to look at how to go about setting up a Learning AI for our video game project and came across the excellent tutorial below. We already talked about simulating crowd behavior using AI a few months ago, but that was really more about pathfinding and if you look more closely at the tutorial that we used in that post, you’ll see that the the definition really falls under Multi-Agent Pathfinding if you want to be specific. Next we wanted to experiment and work with an AI that comes across as just a little smarter that just a drone determining the shortest between a A and B. We wanted something that could learn from experience.

Enter the Learning AI

As we just subtly gave away the definition of Learning AI (also known as Machine Learning), let’s reiterate that thought:

Learning AI, or Machine Learning, is the ability of an AI to learn or improve through experience, without following a specific set of instructions. In a nutshell: AI that learns will work out a problem by itself. This concept, or ability, can be applied to NPC (non-player characters) or even PCG (procedural content generation). Cool, right? You bet it is.

Let’s look at how this is done.

Machine Learning AI in Unity Made Easy

Unity provides the machine learning agents toolkit which you can incorporate and use in your game if you are setting up agents with machine learning. This video uses the sample karting microgame demo and explains how to use checkpoints and a reward system to “train” your AI agents to navigate the race course properly. For example, lose a point for missing a checkpoint, or gaining a point for successfully navigating it. You can of course weight these rewards and other variables differently using transforms.

For a more in depth and visual explanation and to see what’s under the hood of this Karting game demo (think Python, agents and a training environment), check out the following Unity tutorial to see how to easily use the machine learning agents toolkit and apply it to a game with learning AI agents:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.