State-based Spaceship AI

July 8th, 2010| Posted by Andy Korth
Categories: Uncategorized | Tags:

It may have seemed quiet for the last week or so, but it’s because we’re working on some great new AI behavior for Solaro.

We’ve set up a small test village that is modeled after what we think the starting area will look like. This area has three landing pad, a warp gate, and a few mission related items. We’ve got a set of ships that fly from one landing pad to another, trading commodities between locations. We’ve also got a set of patrol ships. These patrol ships intercept other ships, chosen at random, and inspect the cargo using scanners. If they find any contraband, they attack the targeted ship. So how do we do it? With a state-based AI system:

The States:

  • The Seek State: Ships in the seek state simply move towards a specific point. When they get within a certain distance of this point, they will go to the next state in their list. Oh, and we’ve also got some nice obstacle avoidance, so they’ll fly around asteroids and obstacles.
  • The Wait State: This one’s easy. They’ll wait a certain amount of time before going to the next state.
  • The Pathing State: This is somewhat similar to the seek state, but it allows for flying through a set of waypoints. What’s the difference? With the pathing state, we can specify the desired speed and direction through each point, and the ship can fly through them without stopping at a specific point. It’s more powerful and flexible.
  • The Attack State: Kickin’ ass and taking names… and we’re all out of names.
  • The Patrol State: Fly around a specific point at a certain radius and certain speed. If enemy ships come close to the point you are patrolling around, attack them. If they flee, go back to your patrol point. (So already this has proved very useful in missions)
  • The Intercept Target State: Intercept a moving target, and in this case, scan it’s cargo.

So if you’re not impressed yet, it gets better! We can combine these states for UNLIMITED FUN. For example, our basic trading cargo ships do the following: First they start off in a seek state, going to a random landing approach point. They get there and stop, and they automatically go to the next state we’ve queued up, which is another seek state to land on the actual pad. After that, they go into the wait state for 3 seconds and it loops over. We’ve got a simple “DamagedBy” method that will cause these ships to switch into an AttackState to attack whoever damaged them. So it’s very easy for us to customize these behaviors- to make a trader that will flee when attacked, mission specific patrols, and all sorts of good stuff.

  1. Bram stolk
    July 9th, 2010 at 08:14
    Reply | Quote | #1

    Hi there,

    Once your ai gets more complex, your state based system will do more harm than good.
    I advice you to look into Goal Oriented Action Planning, GOAP for short.
    http://web.media.mit.edu/~jorkin/goap.html
    More flexible and more powerful than state machines, but the biggest win is that the programmer gets to keep his sanity when things get more complex.

  2. Andy Korth
    July 13th, 2010 at 08:36
    Reply | Quote | #2

    Hi Bram, thanks for the note.

    We are definitely mindful of the complexities that are possible with state-based AI. One of the ways we’re hoping to reign that in is to limit the complexity of each state, and instead we’re trying for an old trick that has worked pretty well in the past: focus on making simple behaviors that will look believable to a casual observer.

    We originally had some plans to have ships fly actual trade routes- they’d determine what routes were profitable and fly those. If you boarded one of those ships, they’d have the trade goods that made for a profitable route between their destinations. However, that’s a lot of work for something that’s not too noticeable.

    That being said, I think goal oriented AI is really cool, and I’ve looked into it in the past, when I was back in college.

Comments are closed.