Unity + C# + PlayStation Move controller == UniMove!
UniMove is an open-source Unity plugin and set of C# bindings that allows you to use PlayStation Move controllers with your Unity and/or C# application. Currently, the plugin only works on Mac OSX 10.5 – 10.7.
UniMove was created by Douglas Wilson of Die Gute Fabrik and Patrick Jarnfelt of the Copenhagen Game Collective, and is based on top of Thomas Perl’s super-nifty C API. The plugin is licensed under the GNU Lesser General Public License (v2.1 or later), and is still under development.
We think the plugin works on 10.7, but we haven’t been able to fully test it yet. The project works on 10.7. However, in OSX version 10.7.3, Apple introduced a security update to the bluetooth connection, that makes the connecting of the move controllers difficult. To see a guide on how to connect the move controllers to OSX 10.7.3 and up, read this blog post by Doug.
Update 2: Since version 10.8, Apple made a change to the Mac Bluetooth API, resulting in the Library not working. We are working on updating the library so it works on 10.8 and up.
Update 3: Thomas has updated his library so it works with Windows. However, connecting the move controllers to the Windows Bluetooth stack is a pain to say the least. We are still working on implementing these changes to our Library.
The goal, as Thomas Perl put it, is:
… to implement a small and easy to use library to control the main functions of the controller (rumble and RGB LEDs) and to read the sensor values and button states from the controller. The broad availability of the controller, with its USB and Bluetooth connectivity, makes it an ideal candidate for building your own Ambient Orb-style ambient display.
- Set the RGB LED color and rumble intensity (via USB and Bluetooth)
- Read the status of the digital buttons (via Bluetooth only)
- Read the status of the analog trigger (via Bluetooth only)
- Read sensor values of the accelerometer and gyroscope (via Bluetooth only)
UniMove – version 0.1.0 (Beta) (14.6 MB) (July 20, 2011)
- Unity plugin, with full source code and example project
- .dylib file (in case you want to use the bindings outside of Unity)
- Bluetooth Pairing Utility, with full source code
- Start a new project, then go to:
Assets –> Import Package –> Custom Package…
- Find and select UniMove.package
- In the “Importing package” window, press the “Import” button in the bottom right
- Viola! The assets (code, scene, plugin) should now be extracted and visible in your Project window. Double click the “Test Scene” scene to load it. You should now be able to press the Play button to run the test program!
- Provide hooks to the battery level and the temperature sensor (Thomas Perl is currently working on this in his C API)
- MonoDevelop .sln and example C# program (for those of you who don’t have Unity Pro).
- Provide support for the Navigation Controller and other PS3 input devices
- Graphical utility program that offers developers an easy way to visualize accelerometer/gyroscope data, play with LED colors, etc.
- Get the plugin/bindings working on Windows
Email us if you have any code to contribute, or if you want to get involved!
Frequently Asked Questions:
1. Is UniMove available for Windows?
It looks as though Thomas finally got the windows problems cracked. However the bluetooth setup on a windows machine is very dodgy and trial and error. But, the good news is that when the connection is established, the controller will connect and work impeccably.
We are working on integrating the windows dll, into our UniMove library. Stay tuned.
2. I can’t afford a Unity Pro license! Can I still use UniMove ?
Unfortunately, you do need a Unity Pro license in order to use plugins (i.e. external .dll and .bundle files).
However, you could use our C# bindings and make your own project using the MonoDevelop IDE. It’s a little tricky, but definitely possible – we’ve actually done it ourselves. In the near future, we hope to release a .sln (starter project) and short tutorial. Meanwhile, in our download we’ve included the .dylib file (the OSX equivalent of a .dll) that you’ll need to get started. See our .cs files for an example of how to reference code from a .dylib/.dll in a C#.
Careful, it get be frustrating to get MonoDevelop to “see” external .dylib files. You may need to use a special .config file. For more info, read this very useful and extensive page about Mono and interop with native libraties. Also, OSX seems to be picky about how your reference the .dylib prefix and suffix in your C# code. Again, do read that reference page if you’re going to try to use the C# bindings outside of Unity.
Finally, if all else fails, you could always just use Thomas Perl’s lower-level API - available in C, Qt/C++, and Python.
3. Does UniMove work on OSX 10.4 or earlier?
Actually we don’t really know. Update: Thanks to our friend Richard, we’ve now tested it on 10.4. It doesn’t seem to work.
We suspect we could possibly get it to work if we recompiled the .bundle on 10.4. But right now it isn’t one of our immediate priorities.
4. What is a .bundle file?
You’ll notice that the plugin comes with a .bundle file. That’s basically an OSX version of a .dll. Usually, on OSX you’d use a .dylib, but Unity only takes .bundle or .dll files.
If you’re going to try to use our bindings outside of Unity, you’ll want to use the .dylib that we also included (see above, Question #2).
5. How do I connect the controllers via Bluetooth? And what is “pairing”?
This gets a tiny bit complicated. You’ll need to both “pair” and “connect” the Move controllers. Each Move controller stores the hardware address of one target device (i.e. a computer or PS3). Setting that address – that is, tethering the controller to a specific computer – is called “pairing”. To do this, you’ll need to physically connect the controller by mini-USB cable. Once you pair a controller, you won’t ever have to pair it again – or at least until you overwrite that address by pairing the controller to some other device.
We’ve included our own Pairing Utility (along with the source code). Feel free to package it together with your own application. You could also write your own pairing code/utility, of course. See the Pairing Utility code to see how that’s done. Thomas Perl’s original C API actually provides functions for manually setting/getting the Bluetooth address, but we were just able to use his auto-magic psmove_pair() function.
Once a controller is paired, you still need to press the small circular “PS” button to finally “connect” it to OSX (you don’t need the mini-USB cable for this step). If successful, you should see the controller show up in the OSX Bluetooth Preferences panel. Unlike the pairing process, you’ll need to connect the controllers again every time you restart your computer.
Note: if a controller gets unexpectedly disconnected (i.e. it goes out of range), you’ll sometimes need to manually remove it from the OSX Bluetooth Preferences panel before you can re-connect it.
6. How many controllers does UniMove support?
6-7 controllers – apparently there’s actually a hardware limit (7?) on the number of Bluetooth devices that can be connected at any one time.
However, we should note that we’ve found that older/slower computer can have trouble keeping up. This sluggishness seems to increase proportionally to the number of controllers that are connected. We’re still not entirely sure why, and we’d be curious to hear if anyone has a smart workaround. Our own somewhat kludge-y workaround has been to increase, when needed, the frequency of the controllers’ update loop. Our API offers a simple property where you can adjust this frequency. This is why our API doesn’t use Unity’s FixedUpdate() function – we figured that people might want to adjust the frequency of their controllers’ update loop independently of the rest of their application.
A very special thanks to Thomas Perl, who authored the C code on top of which this project is based (and who gave us excellent and patient tech support!). Thomas’ code, in turn, uses Alan Ott’s multi-platform hidapi.
And thanks to the rest of the collective, as well as Brandon, Greg, Tiff, Adam, Marek, Nick, Derek, and Rune, for testing and feedback!
For questions and comments, send us an email.
Version History and Updates:
2011-07-20: Version 0.1.0 (Beta)
First public release! Give it a whirl and tell us what you think!