How to AI by example - Platform follower

1

Attached Files

The following files have been attached to this tutorial:

.capx

platformfollowersimple-nofsm.capx

Download now 182.63 KB
.capx

platformfollowersimple-with-fsm.capx

Download now 183.23 KB

Stats

3,964 visits, 5,706 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 9 Sep, 2014. Last updated 19 Feb, 2019

In my latest tutorial, I gave an introduction to Finite State Machines, and how critical they are as far as AI programming is concerned. This capx-based tutorial offers an example of a platform follower AI, with and without using an "elegant" Finite State Machine. And if you like what I'm doing, you can follow me on twitter and on facebook!

The capx comes in 2 versions:

1- The first one offers one of the most basic platform follower behavior one can make, as well as a captor-based, more elegant alternative.

2- The second capx is simply a re-factored version of the captor approach, using rex's FSM behavior plugin (see links below). I invite you to take a look at it and see how it facilitates the encapsulation or organization of your code.

Installing rex's plugins

In order to open both capx, you'll need to copy the following plugins in your construct folder:

1- The FSM behavior from rexrainbow.

2- The Platform MoveTo behavior from rexrainbow.

Here's a 3 step guide to find and install the plugins:

1- In order to download them, you have to click on the "plugin" link in yellow on Rex's website.

2- Then, unzip the plugins and copy the extracted folders to C:\Program Files\Construct 2\exporters\html5\behaviors (The disk or install folder may be different on your machine)

3- You can now open both capx.

If you want to develop elaborate games using Construct 2, or simply make your design process easier when prototyping, I highly recommend that you check all of rex's plugins. He has made a ton of extremely useful tools for you to experiment with.

"Dissecting" the system

This capx example was made after @christina's request.

The AI has a simple behavior : it targets the player's position, and jumps when it "sees" or comes across an obstacle. It only works as long as the level design is rather horizontal. There is no gap, trap or path detection (although the first two can be added easily).

The AI has 2 states: idle and follow. When it's idle, it doesn't move. It enters the follow state if the player gets too far. When it's in the following state, the AI starts moving continuously towards the player on the X axis. A little object, called captor, is projected forward on the AI's path. This captor is used to detect obstacles when the follower is moving. If it overlaps an obstacle, the AI will simply jump. I invite you to look at the code directly in order to get per-section comments. The system is rather straightforward.

An alternative to the captor would have been to use the "overlapping at offset" condition in Construct 2. I favor the captor mostly as it offers a visual debugging tool throughout development, and can be re-purposed.

Last words

Would you like me to cover something specific? Drop me a message! You can follow me and ask me questions directly on twitter, facebook and google plus.

You can find all of my articles and tutorials about game design directly on my website: http://gamedesignquest.com/ ! Finally, you can find all of my Construct 2 tutorials on this forum post.

.CAPX

platformfollowersimple-nofsm.capx

Download now 182.63 KB
.CAPX

platformfollowersimple-with-fsm.capx

Download now 183.23 KB
  • 0 Comments

Want to leave a comment? Login or Register an account!