Unimove

Unity + C# + PlayStation Move controller == UniMove!

Introduction:

UniMove is an open-source Unity plugin and set of C# bindings that allows you to use PlayStation Move controllers with your Unity game. The newest version works with osx 10.6+, windows and linux.

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.

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. If you can get your Move controllers to connect in windows through the move_pair utility attached here, then using the library in Unity will not be a problem. The problem is getting them connected in the first place.

Features include:

  • Read the status of the digital buttons (Bluetooth only)
  • Read the status of the analog trigger (Bluetooth only)
  • Set Rumble and LED colors (Bluetooth and USB)
  • Read values for the internal sensors (Bluetooth only): accelorometer, gyroscope, magnetometer, temperature, battery level

 Binary download:

UniMove v.0.2.1  (June 21, 2013)

 Source Code:

https://github.com/CopenhagenGameCollective/UniMove

Installation instructions

  1. Start a new project, then go to: Assets –> Import Package –> Custom Package…
  2. Find and select UniMove.package
  3. 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!

 TODOs:

Shorter-term:

  • Provide hooks to the battery level and the temperature sensor (Thomas Perl is currently working on this in his C API) done
  • MonoDevelop .sln and example C# program (for those of you who don’t have Unity Pro). There are other solutions out there for this

Longer-term:

  • 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  It is supported. The bluetooth pairing and connectivity on windows doesn’t get better than it is at the moment.

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 have added the dll to the package and got it to work, but it is complicated. We will post a guide soon.

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.

Go to Thomas Perl’s PS Move API and find the download section. Find the binary files for operating system you have and download that package.  In the Bin folder you’ll find the psmovepair file. Connect the move controller with USB and run the program and follow the instructions provided.

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.

Credits:

UniMove was developed by Douglas Wilson and Patrick Jarnfelt

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:

2013-06-21: Version 0.2.0

2011-07-20: Version 0.1.0 (Beta)