Swarm Motion Control in Adobe Flash

There are lots of examples on the web of people doing motion detection in Flash. Here’s my own script to add to the mix. It’s for an interactive kiosk, but I figured I’d share the base code as it’s pretty fun to play around with. You can download the code here. I’m releasing it under the Creative Commons Share Alike license. If you use it please include a credit line and a link back to my site.

The method for actually detecting the motion has been pretty well documented, but the part that stumped me was how to decide where the dots would go to once a motion collision was detected. The biggest issue with the motion detection is that it detects the edge of the motion, not the entire moving object. Thus it’s hard to figure out where exactly the dots will flee. My solution was to create an animated point that would rapidly swim around the stage. Once a motion collision was detected the dots would begin to “flee” towards that swimming dot. This gives the illusion that the dot is trying to escape from you.

My end product is going to be a bunch of schooling fish so you can see how I’m trying to get their behavior to mimic that.

More From interactive

More Posts