I recently put together a simple class for managing "wandering" motion in AS3, and thought I would share it. It's a pretty flexible class, with a lot of different options:
- specify speed
- x, y, and rotation targets
- specify constant trend strength to move towards the target.
- specify a count and a delayCount to have the trend strength increase over time.
- outer radius specifies the maximum distance from the x/y target the object can move
- inner radius specifies when the trend starts (ie. within inner radius, outer radius has no effect)
- control randomness with varySpeed and varyRotation
- onChange and onComplete callbacks
I've also been playing around with it to make large generative outputs. Nothing really exciting yet, but it's fun: image1, image2.
You can grab the Wander class and a simple demo by clicking here. Beware though, you can waste a lot of time tweaking values and watching the results.
Follow @gskinner on Twitter for more news and views on Flash, Flex, and ActionScript.

Comments (8)
Pretty cool. :)
Could it be easily adapted to one of the 3d engines such as away3d, pv3d, sandy etc?
Posted by: Max at November 5, 2009 09:33 PMURL:
I am not seeing the embedded swf properly. I have the debug player on firefox on mac. It throws lots of errors. The downloaded ones work just fine. Simply excellent.
Posted by: Juwal Bose at November 5, 2009 10:34 PMURL: http://www.csharks.com
Hey Max, I was going to ask the same thing. I've looked into this and it's not that straight forward to do this in 3D. You can't just use SIN and COS on the Z as well as the X & Y. I'd love to know what Math is required to create an orbit in 3D.
Posted by: Lee Probert at November 6, 2009 02:31 AMURL: http://blog.lyraspace.com
Nice job Grant, was just about to do smth like this for myself, but might as well play with your class now :)
Posted by: Milan Orszagh at November 6, 2009 03:01 AMURL: http://ovos.at
Nice, very nice. Thanks for sharing.
Posted by: Tahir Ahmed at November 6, 2009 03:12 AMURL: http://tahirahmed.wordpress.com
I imagine this is how particles orbit kind of on quantum level.
Posted by: Keith H at November 6, 2009 12:03 PMURL: http://keith-hair.net/blog
Hello
Posted by: the a la menthe at November 11, 2009 02:31 AMThis is very good post and you have done a great job.I must say that you are very talented.I have checked those both images which you have given and I like it.I can see that demo too.
URL: http://www.vitabits.fr/the
Hey Guys,
I wanted to use this class in an AS2 project, so I just ported the code (and test file).
You can download the files from here: http://qbesq.com/shared/Wander-AS2.zip
Hope you find it useful.
Posted by: Makram Saleh at November 30, 2009 01:16 AMURL: http://qbesq.com