Artificial Intelligence I – Arrive behavior

Hello everynyan! Was summer vacation long enough? Did you enjoy any relevant videogame or anime series? Please, let me know!

Here, summer was full of great experiences. We organized another meeting with our World of Warcraft guild and it was as funny as always! Also I joined my family for a few days, which is important because they live 500 Km. away from me.

Back to work, I started playing around with the awesome gdxAI, so today I’ll talk about Artificial Intelligence! Doesn’t it sound good? 🙂

I recommend you to download the code from github before continue reading.


  1. About gdxAI.
  2. Steering Behavior
  3. Implementation: Arrive
    • Definition
    • Architecture
    • Concrete implementation
  4. Conclusion

1. About gdxAI

Directly from the wiki:

gdxAI is an artificial intelligence framework, entirely written in Java, for game development with libGDX.

The most important features of this framework are, from my point of view:

Movement AI: Provides different ways of implementing movement on the characters. It includes “Steering Behaviors”, which I’ll use on today’s exercise.

Pathfinding: Allows characters to move across a maze in an independent way.

Decision Making: The machine’s “brain”. I found very interesting how “Behavior trees” work. I didn’t know them yet and it was such a discovering!

Today I will only present gdxAI and the Steering Behaviors concept, and show you how I used the Arrive strategy. In subsequent posts I’d like to explain the Pursuing strategy and Pathfinding, as I have some ideas to apply them.

I strongly recommend you to make a thorough reading of the wiki before continuing with this article.

2. Steering behavior

Although here‘s a much better and complete definition, I’d like to explain them using my own words:

Steering behaviors are a set of algorithms that allow a character to move across the environment in different ways, depending on a strategy.

So, f.i., a monster who follows you when you walk close to him uses a pursuing strategy. When you run outside his range, he will walk back to the point where he was before you bothered him, employing an arriving strategy. Once he’s there, he will implement a wandering strategy, which will make him move randomly inside a scope.

Strategies can also be combined, for example, the enemy could be pursuing you while evading the walls of the dungeon.

3. Implementation: Arrive

PA: To use this, you will need to import the gdx-ai:1.5.0 module from Maven, and update your LibGDX library to the last version.

  • Definition

Arrive behavior moves the agent towards a target position. The target is, let’s say, “surrounded” with two circular areas: The Arrival Tolerance and the Deceleration Radius. The Arrival Tolerance is the area where it is considered that the agent has arrived at the target. The Deceleration Radius is the area where the agent will start to decelerate. The Velocity of the agent should be 0 when it enters the Arrival Tolerance area.


Here‘s a complete description of the class.

  • Architecture

From now on, all the characters that are susceptible to be targeted or need an AI must implement Steerable. It is important to highlight that Steerable does not mean intelligent. A PC can be steerable, but his movements will be defined by player’s input. A mob, nevertheless, will “decide” where to go. In the following diagram (click to enlarge) you will be able to see how Steerable is implemented in the architecture level:


Therefore, PC will implement Steerable through AbstractMob; and mobs, through Automaton. Yes, indirection makes me feel horny. 🙂

  • Concrete implementation

You can find the complete version here.

Now let’s focus on concretions. In previous versions of the code, I used Box2D to make a physics simulation. The dragged Kitten was given a velocity and angle that made him move. The waypoint was a sensor that launched a onCollide event when the kitten reached its range. This event handled the Kitten stop, making its velocity be 0.

It was difficult, it was hard, and it was cool. And now it doesn’t exist anymore. In fact I got rid of the whole PhysicalObjectsFactory. I’m not using Box2D anymore (for now).

Now everything is handled with behaviors. The Kitten will move obeying the Arrive SteerableBehavior. Previously, when the waypoint was moved, we had to notify the kitten that change. But this is not necessary anymore. The kitten will try to arrive the waypoint’s position, no matter what happens. If you move the waypoint, the kitten will automatically follow it.

And we only need a few lines of code to make this work:

See? Kitten extends the Automaton class described in the Architecture point.

In the constructor, it calls the setBehavior method, which creates the Arrive behavior and binds the kitten to the waypoint:

Then sets the Arrival Tolerance and Deceleration Radius areas:

And finally assigns this behavior to the Kitten:

Now changing the position of the waypoint will automatically make the kitten move towards it:

There’s only one good way to test it… Playing with it!


Well I guess this is a good moment to finish the post, although there are some other ideas that I already started working on (if you take a deep look into the code, you may find some sketches). But I don’t want my posts to be too long.

As I said, in the next updates I will implement pathfinding and pursuing behavior, meaning… we will have mobs soon!! Through the viewer’s eyes, when I’m working with frameworks and architectures, it doesn’t look like anything is changing, because the code may have been altered radically, but the functionalities are still the same. So I’m willing to insert some new actors into the scene.

I also worked on the game design. You maybe noticed that the kittens stand up when you put the cursor over them. I will explain this after all the AI theme is finished.

Finally, I wanted to apologize because I realized that I was linking my old posts to the latest versions of the code on github, and not to the concrete committed version. I’m now fixing all the blue links one by one, and I’d be very grateful if you could report any wrong links you may encounter.

Well, thanks for reading! Please Like, Share and Subscribe if you think I deserve it!




Leave a Reply

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

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑