gSkinner - Home

Wander Motion Class Update

Posted on November 20, 2009 by Grant Skinner

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.

Follow @gskinner on Twitter for more news and views on interactive media.
10 Comments

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

Posted by: Evan Mullins on Nov 23, 2009 10:39am URL: http://circlecube.com

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?

Posted by: Max on Nov 23, 2009 8:18pm

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

Posted by: Max on Nov 23, 2009 8:28pm

wow, nice job!

Posted by: aex on Nov 24, 2009 3:46pm URL: http://h43x.com/

Hi, awesome work you made here. Like always :D

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.

Posted by: wickedpixel on Dec 22, 2009 2:34pm

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

:facepalm:

Posted by: wickedpixel on Dec 22, 2009 3:05pm

...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.

Posted by: wickedpixel on Dec 22, 2009 3:19pm

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, ...);

Posted by: Grant Skinner on Dec 22, 2009 7:07pm URL: http://gskinner.com/blog/

2 ice

Posted by: news on Dec 20, 2011 2:58am URL: http://www.reddit.com

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

Posted by: Mattias Hallqvist on Apr 18, 2012 3:58pm URL: http://www.nook.se

Leave a Reply

Your email is never published nor shared.




You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">