Adventures in XNA 6: A Wii Flock of Boids

WiiFlockOfBoidsHere's a flock of butterflies, brought to you in XNA, which can soar around their environment with the help of the Wii controller.

By tilting and rolling the Wiimote, you can control the flight of the lead butterfly. 

The rest of the flock sticks together, chasing you wherever your accellerometer-fuelled flights of fancy take you.

All the butterflies, including the one controlled by the Wiimote, avoid collisions with eachother, as well as with the features of the environment.

[Update: After showing this demo at my Last Stand in Dublin, I posted an updated version of this blog entry on my new blog.]

How it's done

WiiMote Control: I integrated the Wii controller using the Managed Library for Nintendo's Wiimote which I found through Coding4Fun.  It took less than 20 minutes for me to integrate this library into XNA and map the accelerometers to the butterfly's motion, but it had previously taken me 4 days and 8 different attempts to find a Bluetooth adaptor that would work on Vista and speak with the Wiimote. 

I am now using the EPoX BT-DG05A Bluetooth USB Dongle.  Just so you know, the Vista bluetooth stack doesn't seem to talk to the WiiMote at all, so instead, I am using the Toshiba stack installed onto Vista.  The Wiibrew Wiki offers a list of working Bluetooth devices - although Vista seems to complicate things tremendously.  Many of the drivers for the Bluetooth dongles listed as Wiimote-compatible are simply incompatible with Vista, and when I forced two of them to install, they sent me from Bluetooth to Bluescreen.  And the fantastic Toshiba stack will expire in 30 days.  Sigh.

Once I got the Wiimote talking to my PC, having Wii input is very, very, very, very cool.  Note that although this gives Wiimote input for PC games written with XNA, if I published my XNA game to the Xbox360, I wouldn't be able to use the Wiimote.


Flocking: The autonomous butterflies follow the rules of Craig Reynold's classic Boids flocking algorithm, which encourage separation, alignment and cohesion of members of the flock.  They avoid obstacles, and tend towards a target.  Here's the pseudocode that I worked from.

The butterfly's model and animation, as well as the environment, were created by Phil McDarby and originally appeared in Still Life and Mind Balance.


Animation: My butterflies are animated with the XNA Animation Components library, which you can download from Codeplex.  Thanks to David Astle (who leads the project) for sorting out a little bug in the InterpolationController.  Now I can significantly slow down the animation and the engine smoothly blends between frames of Phil's animations, giving the butterflies a really natural look, even when they're at rest.


Future Stuff

I have some ideas for my butterflies that require a particle system, and rather than doing a cheap 'n' cheerful one, I'd like to implement one using HLSL, the High-Level Shader Language, which will give me hardware acceleration.  If anyone wants to give me a starting point for that, I'd be really grateful 🙂

Also, I have some really fun Wiimote ideas in mind, and it's, as always, a matter of hours in the evenings!


XNA Refresh Available 

With the XNA Game Studio Refresh, which was announced yesterday, developers can now package up your XNA games as binaries and distribute them. 

I'd love to publish this game so that you can check it out yourself.  Before I publish the Boids butterfly demo, I need to understand more about how "dissectable" the deployed format is.  I'll get back to you on that one, but for now, happy coding!

Comments (8)
  1. Mykres Space says:

    Robert Burke has put together a small sample of using the XNA Framework, the Wii Controller and a bunch

  2. Bought a Wii remote, can get it to work on XP using a Billionton dongle and the BlueSoleil stack… Can get it to connect on Vista, but the WiinRemote i’m using for testing won’t work (neither the .NET sample)

    My impression is that Bluetooth on Windows has allways been a pain in the ass… At least compared to that fruit company…

  3. Turns out the Toshiba stack and my Billionton dongle worked with the Wii, so now I can use the WiinRemote app 🙂

    So, what’s the deal with IR and the Wii controller..? You use it to get more accurate positioning? Have you used it? Can you use IR on the PC as well?

    The Wii butterflies app looks really sweet btw! Looking forward to playing with the Wii controller and XNA. Thanks for the inspiration.

  4. Myspace presentation: Serving up the long tail’s mp3 and other rich content at scale is an awesome task.

  5. Anolis says:

    I can’t get the toshiba bluetooth stack to connect to the wiimote, it will find it but during service discovery it says that it failed..

    I am using Windows Vista Ultimate x64, AMD 3800+ x2

    and a trendnet bluetooth dongle

  6. krahd says:

    Hi. Many have noticed, getting a dongle to work under vista can be a pain. Here are my humble (and painful) findings:

    * dongle broadcomm + stack broadcomm (widcomm).

    Connects like OK, but does not transmit data.

    * dongle bluesoleil + stack bluesoleil (many versions tried):

    When pairing, the wiimote keeps blinking for ever.

    * dongle broadcomm + stack microsoft:

    Connects like OK, but does not transmit data.

    * dongle bluesoleil + stack microsoft

    not compatible.

    * dongle broadcomm + stack toshiba.

    not compatible

    * dongle bluesoleil + stack toshiba.

    IT DOES WORK (and I got the idea here, many thanks Robert).

    Download it from here: (30 days tryout 🙁 )

  7. krahd says:

    Just a question, does anyone knows where to buy a full license of Toshiba’s stack? thanks.

  8. Robert Burke has put together a small sample of using the XNA Framework, the Wii Controller and a bunch of Community Projects. "Here’s a flock of butterflies, brought to you in XNA, which can be directed with the Wii controller. By tilting and rolling

Comments are closed.

Skip to main content