Actionscript 3 AI Steering Behaviors Library
Big update for you guys! Hey I know I’ve been a bit AWOL on posts lately, but recently I just finished a project which I was on a time crunch to get done. Also I had been having issues with ironing out the last of some bugs with my new big library for you guys. It is an AS3 Artificial Intelligence Steering Behaviors library which works with the game structure code I’ve been writing.
Also I’ve made several adds / changes / fixes to the game structure which I’ll list out below. I wanted to write a big article ( or several ) explaining this big AI library and how each thing works, but I didn’t want to keep everyone waiting any longer so I am going to go ahead and release it now and I’ll write up articles about it as time permits. ( which I have more of now )
For those of you who want to dig in and learn it all on your own go ahead, but for everyone else I promise I’ll get some articles up soon explaining the changes and some tutorials on how steering behaviors work and how I’ve designed mine.
Here is a demo app that I created which shows off everything. You can download the source from the google project page. I highly suggest setting up a repository folder on your PC and keep it updated with the current game library folder, as that is the one which I will be submitting updates to. I won’t be updating the various zips any longer. I recommend tortoise SVN.
So anyhow, here is a list of changes to the game structure that I have made so far. Be sure to check back soon for more AI / Game Structure fun!
ENGINE CHANGES:
- Added more functionality to the Sound Manager class.
- GameFactory is no longer a singleton.
- Added creation of gameworld to GameFactory for easy game setup.
- Fixed dispose function on Entity.
- MovingEntity now restricts its movements to the max speed variable.
- MovingEntity has a MaxAcceleration var, which is mainly just for external use.
- Added a damping variable to MovingEntity.
- Fixed an incorrect math function on Matrix2D.rotateVector()
- CreateCallback function added to Root
- Updated all classes extending EntityParams with the ability to pass variables in the constructor IE:
new EntityParams( { radius:10, type:”Blob” } );
NOTE: be sure to call super( a_params:Object ) AFTER you set any of your defaults, or anything passed in will be overwritten ( by the defaults ) - Added a createCallback function to Root. Quite useful in some cases, check it out.
- Cleaned up Root by taking out the FPS calculation. Use a custom FPS class for this now, such as the Urbansquall one which I am using in the Main() class.
- Added astage width/height const to Root for ease of use. Obviously you will have to change it depending on your games size. - Fixed the lineIntersecton function of the Geometry Class. ( Thanks to Ryan from Mochimedia for pointing this out )
- Added a “getRandomPolygon” utility function to the Geometry class which returns an array of points based on some parameters

(21 votes, average: 4.90 out of 5)




Strid said
am February 9 2009 @ 5:02 pm
awesome
there are many game tutorials out there, but usually they only cover specific mechanics, first time i seeing some material on how to actually build a game entirely, cant wait for next article
are there any OOP/Design Pattern books you would recommend?
i already know some game mechanics, i can code some small games, pv3d and box2d applications, but i feel in need to improve my code organization/design in order to sucessfully build bigger things
Thanks for your efforts in putting all this together!
Colby Cheeze said
am February 9 2009 @ 7:13 pm
Here are two books I read which taught me design patterns. Now PLEASE be sure to rewrite all of the examples that they do and/or make your own small “test/example” apps so that you can make sure you get the concepts. Programming books are no good unless you actually do the exercises and create your own stuff as you follow along.
Head First – Design Patterns ( It is in Java, but very easy to follow if you know AS3. This is the BEST programming book I have ever read…hands down.
OReilly Actionscript 3.0 Design Patterns ( this one is not bad, and in fact to understand design patterns you generally need to read more than one book anyways…at least I did lol )
urbansquall said
am February 10 2009 @ 6:37 pm
Truly epic achievement, Colby. Nice work!
Bob said
am February 10 2009 @ 6:59 pm
Thanks so much for sharing your hard work!
goliatone said
am February 11 2009 @ 5:54 am
Cool, i think the wait was justified at the end!
Great stuff, now I will go mad trying to find the time to play with this
Nick Wiggill said
am February 11 2009 @ 12:02 pm
Great…
I really liked the path movement, circling (particularly the smooth approach path into the circle) and interposition.
You’ve got major bugs though with dodge and hide, also I don’t see what projected arrive and seek is supposed to do…
Thanks for sharing, in particular the flocking should be interesting to look into.
Rgds,
-Nick
Colby Cheeze said
am February 11 2009 @ 1:54 pm
Thanks for the comments Nick. Unfortunately for this post I was unable to explain each of the behaviors fully ( I am working on that article as we speak ) however as a quick answer, projected arrive/seek is the same thing as seek/arrive except that the boid will attempt to arrive at a projected distance from the target ( for instance 100 pixels or so in my demo ) This is a good behavior to use when having units arrive at optimal firing distance from a target..
Steering behaviors will never guarantee that targets do not overlap, only that they will attempt to steer away from each other. Dodge is simply a cheap solution to generally keep boids from hitting each other. There are other better ways of doing this, however I wasn’t sure if they would be as quick to execute in AS3.
I’m not sure what the problem with hide is? It works great for me, although I will say that the obstacle avoidance might seem quite jumpy.
A lot of these behaviors can be altered to act differently and achieve varying degrees of results by adjusting the settings in AISettings.as. Again though, I’ll be releasing an article as soon as I can going into more full detail about how the whole system works and explaining each behavior in more detail.
Nick Wiggill said
am February 12 2009 @ 8:11 am
Hey Colby
Interesting — I haven’t looked into steering myself yet, but dropped by here as it’s a topic I’ll be starting with soonish. The problem I saw with hide is that the “hider” seems to get stuck on the outer edge of the circle pretty badly (perhaps we’re moving the mouse differently?), but if it’s all parameterised anyway, then just a settings issue.
I look forward to your article, and will be around, as I like your content.
Kind Regards,
-Nick
Circstar said
am February 12 2009 @ 1:36 pm
I await your article(s) as well. Great work and thank you very much for sharing. This is a great site that is very informative. Keep up the good work.
Lawrie said
am February 18 2009 @ 3:45 am
Brilliant work, thanks for sharing it.
Neticule said
am February 18 2009 @ 11:35 am
Very amazing man! So many things it can already do, cant wait to see how it evolves. Great job so far
Jonathan @ JADBOX.com said
am April 13 2009 @ 1:53 pm
Hey, your RSS feed is down and your ATOM feed is not up-to-date. Thought you should know.
Anyway, good start on the library here.
Trarman said
am April 22 2009 @ 8:39 am
This is a fantastic sprite framework. I love the extensibility. I’ve already created some new behaviours of my own. One question though: What would you recommend as the best practice for creating new MovingEntities once a screen is already underway? I seem to keep getting single frame flashes of them in the upper left corner upon instantiation.
Colby Cheeze said
am July 7 2009 @ 12:52 pm
I’ve fixed this issue with my newest version of the code. I’ll upload it once I release my next article. For now if you would like to fix it on your own, simply add this to the “ARenderer” class in the constructor.
_canvas.addChild( _container );
_container.visible = false; // set to false initially to eliminate “show in corner” issue at first
Trarman said
am July 10 2009 @ 9:33 am
Thanks! It seems to be mitigated by taking advantage of the reuseClipData method in your BitmapClip class, but plain bitmap sprites still flash briefly in the upper corner.
Montoya said
am July 16 2009 @ 11:21 am
This is simply amazing. I’m very impressed. I’ve been thinking about building some space shooters with “smart” AI so I’m going to follow your development on this very closely.
Chavez_US said
am July 22 2009 @ 11:57 pm
This is done in a 2d environment, do you have any 3d environmental examples?
Colby Cheeze said
am July 23 2009 @ 12:00 am
No, however it could easily be moved to 3D since it is Vector based. Simply add in the Z and update the code accordingly…and Wala! ( I’m sure it’s a little more typing that I let on, but you get the drift )
Actionscript 3 AI Steering Behaviors Library « c# to javascript, actionscript said
am August 14 2009 @ 12:39 am
[...] Actionscript 3 AI Steering Behaviors Library Filed under: programming — zproxy @ 6:38 am I found this nice visulation of AI behaviors at Cheezeworld. [...]
Flash Game Frameworks, Classes and Libraries | der hess said
am September 4 2009 @ 3:34 am
[...] AI Steering Behaviors Library [...]
[Flash CS3] - KI f said
am December 21 2009 @ 7:55 am
[...] Experiments (Revisited in AS3) Zapper’s Labs Finite State Machines for AI in Actionscript Cheezeworld Actionscript 3 AI Steering Behaviors Library __________________ Flash & Actionscript Base64-kodiertes Bild dekodieren und anzeigen, Flash [...]