Saturday, March 23, 2013

Building an AI for Fatal Reaction: A 2D Side Scrolling Shooter


We recently released Fatal Reaction to the Apple App Store. It's a free realtime fast paced 2d multiplayer shooter. The online mutiplayer experience seems to be fun, but there aren't many people playing the game. Most people who try the app can't even fully experience it. At certain times of the day it takes 5-6 minutes to find someone to play against.


Just Some Bots Having Fun (Update Awaiting Apple's Approval)

"Find Players Online" Lets You Search for Players While Practicing!

It quickly became clear that we needed to have an offline multiplayer experience. Writing an AI for such a game isn't easy. The player is in a continuous environment, inputs such as movement speed can range from 0-1 and moving about the level requires various kinds of jumps with different speeds and jump heights. Finally there was the problem of using the weapons. Most of the weapons did instant damage. It is easy to write bots that can own humans at this task. I needed to make bots that were competitive. When I first took on the task of writing the AI, there was no obvious solution.

I decided to break the task up into small easier to digest steps. The first task I decided to take on was that of pathing. The bots need to run around the map and do so in an efficient and natural manner while not getting stuck. The big decision for me was whether to manually feed pathing information or have the app generate the pathing automatically. My main goal was to have the pathing work and work right. I really could not think of an efficient way to calculate the pathing automatically. Even if I could, each device that loads the map would need to recalculate the pathing. After much thought I decided to manually feed it pathing information.


Pathing for the Level Facility

Having decided I needed to manually input the pathing information, I tweaked the level editor to help me. Finally I wrote the code necessary to help me read the pathing information in the game. After going back through my data structures course, I came up with an algorithm to help traverse the map. Soon my AI was running around the level following the player!


Pathing for the level Country Side

Having accomplished the most basic task, I added more layers of logic and decision making to the AI. It added instructions to know when to go on the offense and when to retreat. After adding some randomization to the aiming, the AI started to behave like a human. With planing and attacking the problem one task at a time, the daunting task of writing an AI became feasible.

Preview of the Bots in Action

The new version of the Fatal Reaction has been submitted to the app store. Within a week or so, it will be available on the App Store! If you have an iPhone, iPod Touch or iPad, try out the free app. We are looking for feedback to help us improve the app. And keep a look out for the next version update with the AI to play offline!

Settings Screen for the AI