Saturday, November 16, 2013

Agent Movement: Fleeing and Arriving

Welcome back, my loyal follower(s). Take a seat around the campfire.

It's cozy here.

This week, I'll continue talking about simple agent movement. As you may remember from last post, a good way to improve the movement of your AI is to switch from a simple discrete movement pattern to a seeking pattern. You should go check that out if you haven't already.

Today, we will take a look at the next tutorial in the gamedevtuts+ series on steering behaviors which has two sections:

Agent Movement/Steering: Fleeing and Arrival Behaviors

I'll talk about each section separately because they both showcase different aspects of fluid agent movement. As before, I have my own implementation in my brand-new super-secret public Github, so go check that out, too!

Fleeing is basically the same thing as seeking. This is nice, because it uses almost the same code, so... yeah, I copied and pasted it from one to the other. Not going to lie. The difference, due to vector mathematics, is simply changing the way that you calculate the desired vector.

With a seeking agent, we had it calculate its desired vector by subtracting its position from its target position. Magically, if we subtract its target position from its position, we get fleeing behavior! It's really that simple, and my code demonstrates this nicely.

Fortunately for us, arrival behavior is also easy to add. It's not the same as fleeing or seeking behavior, though. It doesn't calculate a new steering vector for the agent to use. Instead, the code limits the desired velocity when the agent is within a certain distance from the target position. This limit scales with how close the agent is to the target position linearly, which makes it appear that the agent intelligently halts itself right on top of the target position.

This arrival behavior is the first step towards demonstrating some complex additives to the basic seek behavior. In the future, we will take a look at some more elegant ways of mixing and matching movements using a little thing called the movement manager. But more on that later! For now, just go make sure these two new behaviors work for you!

Today's post was a short one, I understand, but it's not too surprising when you think about how simple each new behavior is compared to the initial seek behavior. Next time though, things will get much weirder when we start to look at wandering behavior.

2 comments:

  1. I took the AI 1 class at MIT. I believe there is free courseware available. You might be interested in this class. They use python though :( I hate the python white space limitations but I did well in the class regardless, took some time getting used to python from ruby.

    ReplyDelete
    Replies
    1. Thanks, I'll take a look at it! Arkansas has an AI class, but the professor is retiring before I can get a chance to take it. So it's nice to have a replacement.

      Delete