After watching this video by Mr Thibault Imbert at WiiFlash.org I’ve been wanting to try using the wiimote with the flashplayer on my MacBook. Briefly, WiiFlash consists of a server which reads the icoming bluetooth signal from the WiiMote , and an actionscript library which provides you with an API to access that data.
- Get a WiiMote (about $50)
- Get WiiFlash server from the Download page on wiiflash.org. Differently than what the video says, both Mac and Windows servers are contained in the same .zip file. I just mounted the .dmg and dragged the WiiFlashServerJ.app to my Applications folder.
- Set up a project with the WiiFlash.swc library. The video has an example using FlexBuilder. I just made sure to include the .swc in my library path using mxmlc. Compile.
- start the WiiFlash Server
- Pair your WiiMote (or similar Wii - controller) with the server, by holding down the 1 & 2 buttons. This takes about 5 seconds, then you should see the wiimote listed on the server panel. One thing I’ve noticed is that if you switch the wiimote off , you’ll need to restart the WiiFlash server to reconnect again.
I then found that it didn’t work - FlashTracer was reporting an error to do with a security violation. Thinking that perhaps the movie needed to be served, I tried it on my localhost. No joy. My next thought was that since it is using sockets, it must need a socket policy file. This is something new - you used to be able to set socket policy from a crossdomain.xml file, but not anymore. The socket policy file must be served on a specific socket. There’s a good article about setting up a socket policy server here: http://www.adobe.com/devnet/flashplayer/articles/socketpolicyfiles.html. The bottom line is you need to download the flashpolicy_d scripts and go to the Standalone folder. The depending on whether you prefer perl or python , execute the following command:
sudo ./flashpolicyd.py --file=../flashpolicy.xml --port=843
Or replace .py with .pl for Perl. you might want to put this in a script or just alias it in your .profile/ .bashrc.
And of course the policy xml file should exist at the path specified in the above command. Mine looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
The port number 19028 is the one I saw in the error message from the flash player when I first tried using the wiimote (the port 1024 is for something else, so you don’t need that line).
After that bit of yak-shaving, the test app from the video worked and also the nifty car demo in the papervision folder of the WiiFlash download. The .swf does not have to be on webserver, but can be run in the standalone player.
I’m still getting the hang of the API.. there’s a bug with the yaw property (y-rotation for non-aviators) - it doesn’t seem to work. So I substituted roll (X-rotation) for turning left or right. It was also very jittery as there seems to be some random variation from frame to frame. By averaging the previous and current frame values it gets much smoother. Here’s a demo of a swimming fish, which you should be able to control using a wiimote if you’ve followed the instructions… code follows.
flash 10 required
Now this quickly becomes tricky to control, as it’s sometimes hard to determine the orientation of the fish, and ‘up’ / ‘down’ / ‘left’ / ‘right’ are relative to its own world-coordinates .. which a constantly being modified. I think this would be less problematic if the fish had an identifiable up and down-side.
The FishSwim is a modified version of the one in previous examples.
I’m really excited to have this new input device which seems to be perfect for controlling objects in 3D. I hope to generate some more examples soon, or better yet some games! I will endeavor to make things keyboard-/ mouse-compatible as well, but I think the wiimote offers a more intuitive control for 3D environments, if used correctly.