Crane: Flash Motion Capture Experiment

The “Crane” flash application is a uses motion capture technology to allow you to move a crane arm in flash by moving in front of a webcam. The motion capture coding that made this application possible is called Ostrich (http://ostrichflash.wordpress.com/) and was made available by its creator, Dan Zen, for FREE! Ostrich is only one of a number of complex and unique flash solutions that are collectively called Flash Feathers. Some other interesting Flash Feathers that I will be trying out later include Goose and Dodo, which allow you to incorporate the use of multitouch and blob detection with your flash files.

Crane uses Ostrich in a way that is not documented in the files that the Ostrich download comes with and because of this, I found it quite a challenge to do (I should probably say, I only started using Flash and Actionscript 3 about 4 weeks ago). The challenge of making Crane can from its incorporation of Bones in the flash file. The final goal was to make the “Ostrich cursor” be able to move the Crane which contained an Armature made with the bone tool. Note that the ostrich cursor is created by the code that comes with Ostrich and is internal to your flash file (separate from your mouse cursor).

I will briefly explain where my first attempts when wrong. I began by trying to make the coordinates of the node at the end of my crane equal to the coordinates of the ostrich cursor. This caused the object associated with the this node to separate from the armature and move independently. (fail)

In my second attempt, I realized that when your armature is set to “runtime” instead of “authortime”, you can drag the armature around with your mouse when the flash file is running. This was an important step in the right direction! However, then I tried to you the startDrag function on the object at the end of my crane, thinking that if this object was dragging and moving using the Ostrich Cursor, that the armature had to move with it. This failed as well, the object still detached, I think possibly moving the armature a little when the object was close to it?

Then an idea struck me, I should probably be using the Classes and Methods related to bones and inverse kinetics. This are under fl.ik.* . At this point I finally had search words that would lead me to examples on the internet. That’s where I can across this very helpful blog: http://www.lorenzgames.com/blog/moving-bones-in-as3-and-flash-cs4. Check it out for to find some of the details I may glance over. Note that they coded the ActionScript on the main timeline and I coded in a separate AS file.

To make Crane work, I had to use IKMover to specify where I wanted the end of my crane to go. I made the coordinates used by IKMover equal to the coordinates of my Ostrich Cursor (well actually it was a Point not a coordinate). Thanks to some help from Dan Zen himself, we were able to debug my ActionScript. With so many variable, it seemed like flash was unable to recognize some of them before they were used in the methods or referenced in other variables. Therefore, he added a timer to set off my function related to IKMover after a short delay when the flash file is started.

Future plans for Crane (if I get the time) include making the crane capable of grabbing object (probably clamping using a key press), updating the look of the crane and possibly making object drop when the crane lets go (haven’t figured out that one yet).

I’ve shown my Actionscript below, and I’m writing up a review of Ostrich separately if you are interested to try it out.

If you copy and paste this into an ActionScript file, you can use the Autoformat option to make it more readable.