Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Wiimote Plugin

Discussion in 'Made With Unity' started by bliprob, Oct 19, 2007.

  1. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Sure, I just kind of pasted it together from something you posted earlier, so it probably doesn't work :oops:

    Code (csharp):
    1. private var gotNunchuckData : boolean = false;
    2. private var fromNunchuckX : float;
    3. private var fromNunchuckY : float;
    4.  
    5. public function nunchuckData( x, y )
    6. {
    7.    fromNunchuckX = (x-128) / 128.0;
    8.    fromNunchuckY = (y-128) / 128.0;
    9.    deadenInput();
    10.    gotNunchuckData = true;
    11. }
    12.  
    13.  
    14. public function nunchuckDataX( x )
    15. {
    16.    fromNunchuckX = (x - 128) / 128.0;
    17.    deadenInput();
    18.    gotNunchuckData = true;
    19. }
    20.  
    21. public function nunchuckDataY( y )
    22. {
    23.    fromNunchuckY = (y-128) / 128.0;
    24.    deadenInput();
    25.    gotNunchuckData = true;
    26. }
    27.  
    28.  
    29. function FixedUpdate () {
    30.  
    31.  if (gotNunchuckData) {
    32.         rigidbody.AddRelativeForce (Vector3.forward * fromNunchuckY * f);
    33.          gotNunchuckData = false;
    34.       } else {
    35.     rigidbody.AddRelativeForce (Vector3.forward * Input.GetAxis("Vertical") * f);
    36. }
    37.  
    38. }
    PS. THANKS!
     
  2. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Awesome stuff Rob, I can't wait to play with this!
     
  3. mts2021

    mts2021

    Joined:
    Aug 4, 2007
    Posts:
    150
    Sorry to slightly gravedig on this topic, but seeing the news that brought a rather large smile to my face in regards to the new information about Unity being official middleware, I had come across some info that might prove helpful pending whether its not already all that well known:
    The nyko sensor bar I do not believe is exactly needed for use of the Wiimote.
    Its not really a 'sensor' bar at all, its more like what the predator threw down in the AVP2 movie. its more like putting a place holder down so that the Wiimote can triangulate what position(s) the Wiimote is in.
    If you take a few just regular remotes from your tv and hold them in front of your Wii or remote, it should use the LED or reciever to pinpoint where the remote is.
    irratic yes, but I believe for a quick (and not to mention cheaper) method of dev kit related testing, a cheap battery powered wireless unit should work just as well, with little or no wireless interference, or so I'm told.
    Check Youtube for homebrew methods, as well as other options for having the remotes check their positions cheaper.
    Its just leds. ;)
    Hopefully this proves helpful for future Wii Development. :D
    BTW... Kick Ass work for the plug in for sure man.. hope to hear more as the code is refined and mainstreamed.

    http://www.engadget.com/2006/11/21/wii-sensor-bar-hax0red/
     
  4. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    Any further tips on getting Uniwii to recognize the Wiimote? I've tried for 20 minutes and it just won't. I can (sometimes) get Bluetooth Setup Assistant to recognize it, but whether or not I continue with that process to get a passkey (not applicable, I assume), and whether or not I use the 1-2 buttons or the red synch button, Uniwii won't recognize the Wiimote. Once I got the confirmation rumble, but usually I don't, though I still sometimes get one blue light at the foot of the Wiimote indicating a connection.

    TIA
     
  5. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Here is the setup I followed:

    -get bluetooth set up assisstant to recognize it (no need to get passkey/continue with process).
    -press red button on wiimote to sync.
    -open up application.

    I found that if I don't sync it BEFORE open up my application, it won't connect. I hope that helps
     
  6. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    Got, it, thanks, though I had to press Synch again after launch uniwii. Awesome!
     
  7. boomaster_legacy

    boomaster_legacy

    Joined:
    Feb 24, 2008
    Posts:
    262
    I find this amazing and all, but I seem to be missing it. How do I put a wiimote function into my game??? :?: Nice videos too. :) (i know that i do need a wiimote, IR bar, and a game for it... ;)
     
  8. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    You need to download the plugin from the wiki (this requires pro)--http://www.unifycommunity.com/wiki/index.php?title=UniWii

    There are instructions here on how to set up little test applications. Once the plugin is in the appropriate folder in your project you can just incorporate data from the wii controller as variables in scripts.
     
  9. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    And note that plugins require Unity Pro.
     
  10. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
  11. Joe-Robins

    Joe-Robins

    Unity Technologies

    Joined:
    Apr 21, 2008
    Posts:
    430
    Hi Unity people... I'm having great fun with this plugin! your efforts are much appreciated!


    I have managed to get the majority of things working, the YAW I seem to be having problems with using the rotation script in the Wiki.. maybe I am getting it wrong but I can't seem to hook it up correctly with the Y axis...


    The other thing (probably more importantly) that I am struggling with is the IR script... The problem I am having is when it comes to displaying the cursor on the entire screen. At the moment the height isnt too bad.. but the width seems very limited, is there something I am missing in terms of calibration?
     
  12. crockett

    crockett

    Joined:
    Apr 11, 2008
    Posts:
    264
    Just a thought here, but if you can get the wii remote to work with unity, wouldn't that also mean we could get TrackIR to work with unity?

    http://www.naturalpoint.com/trackir/

    It uses the same basic idea of the wii remote but the system is set up in reverse. So rather than tracking the moving remote. The IR is set up stationary and it's tracks the reflector which is set up to allow head movement and looking around inside games.
     
  13. Joe-Robins

    Joe-Robins

    Unity Technologies

    Joined:
    Apr 21, 2008
    Posts:
    430
    Yeah this is what I am looking into at work at the moment... (although due to other projects my research is being put on the back burner)
     
  14. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I've done a head tracking demo with Unity. I think it's posted on this thread, but probably many pages back:

    http://www.robterrell.com/UnityHeadtracking01.mov

    The gist: I bought a pair of the safety glasses and replaced the visible light LEDs with IR LEDs. I made a simple space skybox with a moving target (you briefly see it in the movie).

    The other thing I did in this demo was voice activation. Using the HTMLTexture plugin, I am able to get access to the microphone (using a 1-pixel Flash movie). The idea was to let the user point their head at the target, and yell "fire!" to blast away. But I never got the missiles to properly fire. (I kind of got bored once the nifty stuff was working.) However, you can see the mic level meter working in the movie.
     
  15. crockett

    crockett

    Joined:
    Apr 11, 2008
    Posts:
    264
    Nice to hear.. I may have to hit you up sometime in the future. A game I want to do requires the ability to look around freely. I want to give the players the ability to use their keyboard number pad, joystick hat switch or a head tracking option.
     
  16. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    About the Yaw, pitch and roll the plugin offers:

    To me these three angles don't seem real euler angles. I have been looking into the source code of the Darwiin Remote Framework and it seems that they don't give this angles, so I deduce that it must be some calculation Rob makes inside the plugin.

    I was going to look into the raw accel values, but I dont know how to interpret them. It seems that the darwiin framework offers them as unsigned shorts, while in the plugin they are bytes. Also, they are based in 0x80. I'm looking into http://www.wiili.org/index.php/Motion_analysis to understand how to interpret it.

    EDITED: Substracting 128 from the raw values I get, it seems that the direction is correct (z positive when the controller is flat on the table, etc...). The problem is the magnitude. The values are capped between +27 and -27, more or less... I never get values bigger or smaller than that.

    Everything works ok if I use the DarwiinRemote app (values between -1.0 and +1.0, etc)

    would it be possible to have the uniwii plugin source code so analyze it and maybe contribute?

    Many many thanks
     
  17. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    John, you are correct, the WiiMote doesn't return euler angles. What it returns is the X and Y values of the WiiMote (-1.0 to 1.0); if I recall correctly, the raw values are coordinates for each of the IR sources. To properly perform head-tracking, you need to use the raw values to calculate the angle of rotation. Or you can try to infer it from the pointer (x,y) values.

    In general, my preference is to have the plugin avoid making calculations for you; you can do whatever you like to the data it provides in your c# class.

    I haven't seen the +-27 issue. What version of DarwinRemote are you comparing it to? The plugin is using .5 or .6 at the latest.

    EDIT: You must have a different version of the Darwiin framework, because my copy doesn't use shorts for the raw data. I'll look at updating the framework as soon as I'm done with the htmlTexture update I'm working on.
     
  18. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Yes, I have the latest version of DarwiinRemote (0.7). but that shouldnt affect anything, your plugin is compiled and linked directly with your local version of the Framework, isnt it?

    At rest on a flat surface, I get the following values for raw accelerations:

    accX: 132 accY: 134 accZ: 159


    is it possible that +g (1 earth's gravity) equals to +32?

    So max acceleration would be 128/32 = 4g

    Thank you Rob!
     
  19. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    I just set up everything as described here only without an IR bar.

    When I run the sample code, the on-screen object that I have the Wiimote controlling always begins oriented with its RPW oriented away from 0,0,0 yet always in the same position.

    Is this because I am not using an IR bar?
     
  20. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Hey, everyone!

    I've tried the plugin with two Wiimotes and both start up with the mesh being driven by the Wiimote plugin at an odd angle -even though the Wiimote is being held perfectly level and pointed forward.

    Any idea what might cause that?
     
  21. anti-alias

    anti-alias

    Joined:
    Nov 8, 2008
    Posts:
    62
    Hello bliprob,

    I read that you ported your wiimote plugin under XP. Is it possible to try it? I build a VR application (started in Quest3D) and need to control with Wii, but it only works on OSX as I now. Thanks a lot.
     
  22. MrSweet

    MrSweet

    Joined:
    Jan 19, 2007
    Posts:
    143
    Hi Bill

    Would you upload/send me the FPS Tutorial Project Files so i can would out how the controller works with Nun Chuck etc

    Thanks

    Andy
     
  23. MrSweet

    MrSweet

    Joined:
    Jan 19, 2007
    Posts:
    143
    Hi

    Can anyone help with the code need to get the FPS working?

    Thanks
    Andy
     
  24. niyus

    niyus

    Joined:
    Nov 20, 2008
    Posts:
    37
    this looks great! what is the major difference between darwiin remote the uniwii?

    i am a student so cant afford the Unity Pro but have bought the wiimote and nunchuk to make a single player fps game with wii gun...does anyone know if i can do this easily with just the darwiin remote? i've been testing but having some problems with navigation and then i saw this thread...

    many thanks for any help!
     
  25. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Andy -- The FPS Wiimote source is now available at http://robterrell.com/FPSTutorial-Wii.src.zip

    niyus -- Darwiin remote is a stand-alone app, whereas the plugin is bundled into your game. If you want to distribute your game, you're better off with a plugin.
     
  26. anti-alias

    anti-alias

    Joined:
    Nov 8, 2008
    Posts:
    62
    Hello,

    I'm glad you are back. How can be used your wii-plugin under win XP? I read that you planned to make it work under Windows. Is it possible to share it somehow? Thank you.
     
  27. MrSweet

    MrSweet

    Joined:
    Jan 19, 2007
    Posts:
    143
    Cheers, let me check it out.
     
  28. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
  29. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    By googling "Wii balance board" and "OSX", I just found an interesting modified version (with binary and source) of DarwiinRemote that supports the Wii balance board :

    http://rickvanderzwet.nl/trunkplaza/darwiin-remote/

    ...and here a video tutorial, appearently made by the author :

    http://www.truveo.com/Navigation-with-Wii-Balance-Board-into/id/4191022758

    As soon as it connects with a Wii balance board, the app displays an interactive picture of the device :
    Red spots vary in size according to your position on the board, and the exact "weight" detected on each corner is displayed in the 4 text fields.

    By default, you can already use this setup to control any game that reacts to a,d,s,w keystrokes - Unity car games, for example. Pretty exciting, really : I spent 30 mns riding on my home-made mountains today - and it was real sport ! :D

    But - unless I missed something - this solution is far from ideal, since those key messages cannot be mixed together : to turn left or right, you first have to stop going forward, otherwise nothing will happen. As for the real "weight" values, there seems to be no way of sending them out (through a file or network connection) in order to get them into Unity and have the character controllers react in a much more natural way.

    So... an updated version of Rob's excellent plugin that would fully implement the Wii balance board would be a wonderful thing : could allow us to develop incredible sport apps with Unity. Imagine yourself debugging your games while making sport, all day long... :)
     
  30. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
  31. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I actually got a WIi balance board last week for Valentines' Day (I suppose that means, she loves me, but I could lose a few) and I've started to get it working. If there's demand I'll move it up the priority list.
     
  32. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Wow Rob, that is great news ! Thanks a lot for sharing it :D :D :D
     
  33. timeisaparallax

    timeisaparallax

    Joined:
    Sep 22, 2008
    Posts:
    35
    So for a class I made two different games involving the UniWii bundle. The first was mostly a tech demo but the second one is pretty serious and I'd like to put it in my portfolio.

    My problem was and continues to be connection. Wiimotes used to connect on average 1/3 times. Now they will rarely connect and when they do it is only one of the two wiimotes I am trying to connect. I tried connecting about twenty times and half the time I could get one to connect and the rest of the time I could get none. I seem to have better odds when I remove the wiimotes from my blue tooth preferences, and yes bluetooth is defiantly on.

    I saw another person with a similar issue earlier but I could not find a response from anyone on suggestions for that person.

    Any help is greatly appreciated!

    ::EDIT::

    I am also certainly willing to help in away way that I can. I'm also willing trade A* code/do some coding/buy a round at GDC if there is anything anyone can do to help me out.

    Thanks!
     
  34. jonnex

    jonnex

    Joined:
    Sep 22, 2008
    Posts:
    13
    is there any way to make this plugin work with Unity Indie? I just started trying to get it working, only to be greated with 'licence error, plugins only supported by unity pro'

    :(

    any way to get it working with indie?
     
  35. TheLorax

    TheLorax

    Joined:
    Mar 25, 2007
    Posts:
    86
    Throw my vote in for one who would like to see the Wii Board working with the Unity PlugIn!!! I've had my students use the plugin before, and incorporating the Wii Fit Board would be a fun class project!

    Thanks

    TheLorax
     
  36. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hi jonnex,

    Plugins are supported only on Unity Pro!

    http://unity3d.com/unity/licenses
     
  37. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    You actually can have "plugins" in indie, but only managed .NET dlls. The scope of things you can do is more limited than C++ plugins, and there are some more restrictions for webplayers that used a thin version of Mono.
    You can have a look at this managed C# library, never tried it myself but I'd be curious.

    If you only want to play around and don't care about deploying, there are also drivers that can map virtually any input to anything at OS level, so you can transform your wiimote into an HID gamepad.
    Those guys even transform a webcam into a gamepad!
     
  38. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    The managed c# library will work from Unity fine, but it doesn't work in a web player (due to the p/invoke native calls). Nor does the plugin, for that matter.

    I have updated the plugin to report all four raw IR values. (Mac only for now.) I'm waiting for a tester to give it a clean bill of health before I release the bundle.
     
  39. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Interesting... but if it does native calls, then it's not managed? :?
    Do you know this lib? is it Windows only?
     
  40. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I evaluated this library when working on the windows version. It's a great library. You can download it from here: http://www.codeplex.com/WiimoteLib

    It's Windows only due to the native Win32 API calls it makes to talk to the bluetooth stack.

    (The library is still called managed, even if it calls into unmanaged code.)
     
  41. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    OK... so it should be easy to just load the 2 plugins into Unity and make a wrapper that uses the right one depending on the platform, right?

    Thanks for the explanation!
     
  42. EricT

    EricT

    Joined:
    Mar 25, 2009
    Posts:
    6
    I am just trying out Unity for the first time (on Windows PC) and need to get input from a Wiimote. I have been using wiimotelib for other C# applications but am having difficulty making it work with Unity.

    I create a new Wiimote in Start() with;

    mWiimote = new Wiimote();

    but then;

    mWiimote.Connect(); gives an IOException.

    Has anyone had success with this and perhaps an example to share?

    Thanks!
     
  43. dhill

    dhill

    Joined:
    Mar 29, 2009
    Posts:
    15
    I'm having the same problem. These lines in Wiimote.cs

    Code (csharp):
    1.  
    2. // create a nice .NET FileStream wrapping the handle above
    3. mStream = new FileStream(mHandle, FileAccess.ReadWrite, REPORT_LENGTH, true);
    4.  
    result in an invalid handle error. But apparently the handle (mHandle) was valid enough to find the wiimote in the first place. Is there something blocking Unity3D from connecting to the device?

    If someone has had success with this, please let us know. I'd love to see how head tracking works with Unity.
     
  44. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
    Has anyone got Wiimote working with indie?

    Has anyone got Wiimote working with Unity Pro?
     
  45. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Yes, you can use the Wiimote plugin to use a Wimote with Unity Pro.
     
  46. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
  47. dhill

    dhill

    Joined:
    Mar 29, 2009
    Posts:
    15
    bliprob is the one with definitive info on this, but my understanding is that the wiimote plugin is a Unity3D plugin for the Mac only, and WiimoteLib is a .net dll for Windows -- two different things. WiimoteLib uses native Windows calls and so is not portable to the Mac, and I do not believe that the wiimote plugin has been ported to Windows yet and I don't know if there is any intent to do so.

    I haven't had success calling WiimoteLib from within a Unity3D game yet. My plan is to have the game read wiimote data from a SQLite data file, and have two different Mono programs, one for the Mac and one for Windows, either of which can connect to the wiimote and continuously update the database. That will keep the platform-dependent part out of my game, at the cost of having a separate step in launching the program. That should be acceptable for my (academic) purposes, though maybe not for anyone else.
     
  48. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    UniWii is the name for the Unity plugin (native code) I wrote. WiimoteLib is a DotNet managed DLL. They're very different animals.

    UniWii is available for Mac on the Unify wiki. A Windows version of UniWii (with the exact same API as the Mac version) has been completed and will be available by the end of the month.

    Both the plugin and the DLL have the same deployment limitation (not for use in web player). The DLL is Windows-only, since it uses P/Invoke to call into the Windows device manager. The plugin is cross-platform (soon), so I think it's a better choice than the DLL.
     
  49. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Does anyone knows how do I calibrate the orientation of the wiimote on this plugin?
     
  50. Silvia

    Silvia

    Joined:
    Apr 18, 2009
    Posts:
    23
    I'm getting headache trying to understand WHY on Earth this happens, but I really can't solve it. Is there any kind person out there who might help??