Do you ever ponder about the best way to create artificial intelligence for games? Well, me too! After years of industry experience and research, it still fascinates me. But one thing is certain, it requires lots of practice…
This article launches a series of tutorials, every Wednesday on AiGameDev.com, building game AI from the ground up. The plan is to focus on incremental improvements with tangible benefits at each step. Of course, over the months, it’ll hopefully turn into a showcase of current game AI techniques.
Figure 1: Different dog behaviors.
The simulation game involves dogs interacting together, though the design is pretty open at this stage, as it’ll be refined incrementally based on your contributions! (Be sure to join the discussion each week by leaving a comment.) This week in particular, you’ll find out what’s in place already and what the plan of attack is.
Before creating the AI, you’ll need the basic ingredients of a game first! This tutorial relies on simple assets and a game engine.
- Models & Animations
It’s tough to find good models and animations online, so often the best solution (if you want things to look good in the end) is to buy “stock” assets. In this case, the models look fine despite being low-poly, but they reveal a few glitches when animated. The animations won’t win any awards, but they’re better than programmer art.
Specifically, the animations available are:
For movement, there are animations for walking, jumpy run, turn left or right, strafe left or right, sneaking and limping.
There are also different postures (including transitions) such as lying down, standing on two legs, sitting and sleeping.
In terms of interaction, there are animations for picking-up, sniffing, licking, eating/drinking, peeing, pooping, begging and fighting.
Other behavioral animations include, high and low jump jump, barking, scratching, chasing tail, growling, and excitement.
No doubt it’ll be necessary to tweak the animations into a AI-friendly format, for example to add missing looping animations, or correct existing ones. Also note that all the animations are modeled at the origin, so there’s no movement in the animation data. (This affects the design.)
- Game Engine
While many open-source engines have similar features, the plan here is to use Ogre3D. It provides exporters for the models and animations, and stores them in its own format for easier loading. At runtime, Ogre provides an API to play each animation, control their speed, and blend between different animations. Of course, it’s trivial to move around any entity in space using the scene manager.
- Artificial Intelligence
You don’t need anything but a 3D engine and assets to start programming AI. However, this tutorial series will be developed alongside Game::AI++, an open-source library that’s in early development stages. This project will be a good opportunity to iron out the rough edges in the parts of the framework that are already implemented. Rest assured though, re-implementing the ideas in the tutorials won’t require using Game::AI++.
At this stage, all the basic elements of an interactive simulation are already implemented. The game view opens, models are loaded and can be displayed on screen.
Screenshot 2: Two inanimate dogs with static skeletons.
The next step is to work on the most basic AI features. Typically, the best place to start is to write the logic to control each actor, in particular:
Moving Around — The 3D engine already supports most kinds of transformations, but these need to be exposed in an AI-friendly way. Specifically, all movement needs to be done relatively to the current position, and the parameters of movement must be easy to tweak.
Playing Animations — Again, the animation system in the engine handles posing the skeleton from keyframes, but there needs to be an easy to use interface for each actor in the game. Options such as playback speed and looping should be easy to specify also.
First Design Ideas
Here’s where you get the chance to think of simple designs that can be achieved with this simple technology. This week, there are some important restrictions:
The behaviors must be applicable to individual dogs only.
The behaviors should not require reacting to the world.
Anything else goes, so feel free to share your scary ideas about this game! Think along the lines of behaviors that are sequences of different animations and movement.