Wander Motion Class Update

I just uploaded an update to the Wander motion class I released a couple weeks ago.

This version has some new features that I’ve added as I needed them, like:

  • targetObject: set the Wander to use the x/y of another display object as it’s target x/y. There are lots of possibilities with this: you can follow another wandering sprite, follow a sprite moving in a completely different way (ex. a bouncing ball), or even follow a sprite that was tweened in the timeline or via a tweening library.

  • rotationLimit: sets a limit on the maximum amount that the rotation can change in a single update of the wander. You can use this to get nice smooth arcs and more gradual responses (particularly when using targetObject).

  • update(): you can set autoUpdate (which replaces paused) to false, and call update directly if you have a central tick dispatcher.

  • getShortRotation(): exposed this helper method for general use.

  • always operates on the target’s current rotation. Now you can change the rotation between updates, and Wander will use the new rotation properly.

  • oldRotation: stores previous rotation value.

  • fixed a couple of minor issues.

  • included FLAs for the demos.

Here’s a simple demo that uses targetObject and rotationLimit. It’s included in the download. It shows 200 wandering sprites with rotation limits following another sprite with a high varyRotation setting and no rotationLimit.

You can download the updated version, with docs and demos by clicking here.

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

10 Comments

  1. Very Cool! Thanks for sharing this, I hope to have an opportunity to use this real soon. I’ll share when I do.

  2. Nice work.

    Does it have a 3D interface to use in away3d, PV3D etc?

    Would it be easy enough to implement a z coordinate if you haven’t already?

  3. Didn’t realise I had already posted this question previously, but I did a quick google and saw these 3d flocking articles:

    http://blog.inspirit.ru/?p=231

    http://blog.onebyonedesign.com/?p=282

  4. Hi, awesome work you made here. Like always 😀

    One question… Is there an easy way set the initial rotation/direction for particles? At this moment they all go to the right at start.

  5. eh, well.. nevermind… i need to read better the manual. targetRotation was for that.

    :facepalm:

  6. …now i’m spaming 🙂

    What i needed was to do create particles like this:

    wander = new Wander(clip,{params…});

    wander.target.rotation = degree.

    where degree is the initial direction for the wander particles, in degrees. default is 0.

    ok. now i’m gone for good.

  7. wickedpixel – right, the Wander class will use the rotation of the target. So as you said, it’s just:

    clip.rotation = initialRotation;

    wander = new Wander(clip, …);

  8. Hey.

    I’ve known this class existed for a long time but today I got a reason to use it. Yay!

    Just a minor thing. The props object initializer (“null”) indicates you don’t have to pass an object, but you do, otherwise this line causes error:
    if (!(autoUpdate in props)) { props.autoUpdate = true; }

    cheers

Comments are closed.