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
Here’s a demo you can use to play with the different settings:
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.