Search Unity

  1. Click here to receive a gift with your purchase of Unity Pro or Unity Enterprise.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Wiimote Plugin

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

  1. SoLike

    SoLike

    Joined:
    Apr 14, 2009
    Posts:
    4
    Same problem here.. I also tried to use the wiimote in windows using the wiimoteLib, i also got an invalid handle to the wiimote.

    Which is strange because the exact same code works perfectly in a c# app.

    The thing i did was write a simple c# program that reads the data from the wiimote and write it to a text file. Next i read the values from unity and use them in my game.

    I know it's a very ugly solution but we can continue with are development until the problem is solved. Or someone comes up with a working plugin.

    Hope this helps
     
  2. Silvia

    Silvia

    Joined:
    Apr 18, 2009
    Posts:
    23
    It happens that Unity 2.5 for Windows is based on a quite old version of Mono, which by the way does not support FileStreams (needed in WiimoteLib to maintain the communication to the Wiimote). That is, WiimoteLib won't work on Unity 2.5, unfortunately.

    I suppose I'll have to turn to reading data on file like SoLike suggested, even though it looks like a very ugly solution to me.
     
  3. SoLike

    SoLike

    Joined:
    Apr 14, 2009
    Posts:
    4
    I know it's an ugly solution, you could also use rpc's or shared memory, better but still ugly..

    Btw i'm using a FileStream and a StreamReader to read and write from one file simultaneously, so a FileStream does work.

    I don't see any other solution at the moment.
     
  4. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    This is courtesy my co-worker, he is emailing the Unity support staff about this...

    from the WiiYourself! TODO:
    apparently SDL's joystick enumeration (which Unity does use) disrupts the bluetooth stack in some way (on windows) making wiimote connections problematic
     
  5. SoLike

    SoLike

    Joined:
    Apr 14, 2009
    Posts:
    4
    I hope they can fix it!

    Keep us posted :D
     
  6. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    What seems to actually be happening is Unity enumerates the wiimote as a joystick and holds on to that handle and the wiimote libraries are unable to obtain a proper handle for connection.

    It seems our current workaround will be connecting the wiimote before launching Unity, and using a modified WiimoteLib that connects via named pipe.

    This is no where near ideal and it is making us sad :(
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,602
    Unsure about that.
    There is a general problem with accessing any kind of streams in Unity 2.5, the common answer from unity is that it was not able to do it because it is already in use.
    This happens during build, during usage of System.IO but also in other cases.
     
  8. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    Yeah, I don't think it has anything to do with the BT stack any longer, but just with accessing the HID device itself. Unity seems to want to own the wiimote even though it can't do anything with it.
     
  9. Shadowrat

    Shadowrat

    Joined:
    Jun 3, 2009
    Posts:
    16
    I just recieved word back from Unity. It's great that they replied so fast.

    I asked if i could disable discovery of joysticks or get code to run prior to unity initializing.

    I was told they couldn't provide any information on the subject.


    Ah well. I didn't have high hopes of them helping fix this issue. connecting wiimotes on a pc is really a big hack.

    I'm about to test the named pipes implementation. Hopefully it works out.
     
  10. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    Named pipes failed, so is this a limitation of the embedded Mono?
     
  11. Shadowrat

    Shadowrat

    Joined:
    Jun 3, 2009
    Posts:
    16
    All the techniques we tried revolved around using the winapi CreateFile function.

    it seems unity is doing something to prevent that function from working.

    Our current solution is to provide the current wiimote state via .net remoting. It seems stable and fast enough. It's hardly ideal, but it works.
     
  12. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    472
    Apparently named pipes are broken in Unity's version of Mono (which dates from around the mezozoic era).
    I've been told that you can use TCP/IP (is that what others call .NET remoting?) to circumvent that, from what I understand the architecture is basically the same and the implementation could even be easier than named pipes.
     
  13. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hey guys... the Windows version of the plugin is now available on the Wiki!

    Brought to you by the awesome Rob Terrell of Stinkbot and via me with ByDesign Games, the Windows downloadable includes Windows support (ORLY? haha), a test scene + sample code + an interactive Wii-mote model. Plugin is Pro only for now (sorry Indies!)



    Some bits are yet WIP, but post here or on the Wiki article's discussion page if any issues.

    Enjoy! :)
     
  14. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Joe, could we track 4 individual IR leds with this somehow ?
     
  15. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    If you don't mind my asking...

    How on earth did you get around using File Handles to access the wiimote?
     
  16. Silvia

    Silvia

    Joined:
    Apr 18, 2009
    Posts:
    23
    Same question from me! From what I had found out, it seemed an awful lot of work. [/quote]
     
  17. PressTheLocateButton

    PressTheLocateButton

    Joined:
    Feb 24, 2009
    Posts:
    51
    We had tried to shoehorn WiiYourself! into Unity as a plugin, but the file handles shot us in the foot, so I am awfully curious about how this problem was resolved for this plugin!
     
  18. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Bart: yes, the windows version will track all four LEDs.
     
  19. ttt121

    ttt121

    Joined:
    Oct 20, 2008
    Posts:
    18
    thanks for this plugins~ I use it in my win7 is no problem.

    But I use it in any winxp,it show me this error every time every PC,any one has this error?help me
    pls~ my Unity is pro
     

    Attached Files:

  20. fishhook

    fishhook

    Joined:
    Aug 3, 2009
    Posts:
    3
    hi,
    for some reason uniiwii has stoped detecting my wiimote, it was working fine before i had to change the batteries, but now my bluetooth says the wiimote is conected and recieving data when i press buttons, but unity/uniiwii seems to be ignoring it. im trying to use this for a uni assignment/project and need it to back up and running asap, i have a ton of work still to do :(

    any ideas/ help would be great.

    thanx

    edit:: a little extra info, even though the bluetooth says the wiimote is connected, the lights on the wiimote will not stop flashing, im unsure what this means, but might explain something to some that does.
     
  21. Almar

    Almar

    Joined:
    May 11, 2009
    Posts:
    87
    Hm, Somehow I am running into problems as well. We are developing various small games, and in the Exe version it does not seem to connect to the Wiimote, while the driver (bluesoleil) does say it is connected.

    In Unity IDE everything is perfect. I already copied the DLL in each directory possible just in case.

    Anyone with similar issues?


    Edit: Nevermind, seems I have to close Unity and it starts to work again. I will leave this as reminder for other users.
     
  22. Almar

    Almar

    Joined:
    May 11, 2009
    Posts:
    87
    Hey everyone,

    I've ran into quite a problem. Our games (four minigames) are due to be finished, so I started testing on different machines.

    But I am unable to get the games work, at all. Only removing the wiimote_start() will make the games come alive and actually do something. I've tested the games on multiple computers/laptops but they all suffer from the same issue.

    All the machines run XP, and I use the same Bluetooth stick and driver (BlueSoleil). The UniWii.dll is nicely copied when building the game, and I can run the game on this machine without a problem. Copying the dll to other locations in the directory does not seem to help...

    Sounds to me like this computer has something what others do not (Unity itself for example), and it's probably something like this. Does anyone have suggestions what it could be?

    I know everything is quite vague, but there is not much more I can make from it ;).

    I will try installing the latest VC runtimes to see if that will solve the problem.

    Edit:

    Jeesh, and that is actually the solution! Installing the VC 2008 SP1 Redistributable package from Microsoft's site instantly fixes the problem!

    It's getting a habbit to fix things just after posting about it ;).

    I've added some information about it on the wiki as well now.
     
  23. enmeii134

    enmeii134

    Joined:
    May 25, 2009
    Posts:
    31
    Hi, bliprob.
    I am doing a project on PC which using the uniwii plugin.

    But I have some troubles, can you give me some suggestions please.
    1. I can't get Yaw, I used the function "wiimote_getYaw", but the plugin returned me "0" anyway.
    2. Can I get the position value of wiimote?
    3. How can I use IR system?
    4. I can't move the remote very fast, if I do it quickly, no feedback. Can I make the remote more sensitive?

    Sorry, I'm not a English speaker, if you can't understand what I said, please let me know. I am very hurry.
    Deeply grateful here.

    -Enmeii
     
  24. Almar

    Almar

    Joined:
    May 11, 2009
    Posts:
    87
    This does not work for me either.

    What do you mean with position? The "Screen position"? Like a mouse cursor? You will need to use the sensor bar (or any other source of infrared) and then the wiimote_getIrX(int which) and wiimote_getIrY(int which) functions to get a relative position from -1 to 1 I believe. This can easily converted to screen corodinates; I can posr some code later from work. (Monday)

    By putting the sensorbar somewhere and supplying it with some power ;). I use 9v battery. I could make a photo of that as well on Monday. Or during development you could theoretically just turn on the Wii itself and connect the sensor bar to supply is with some volts ;).

    The acceleration sensors will always return values for me, but the GetPitch/Roll functions will indeed stop returning values for me as well when the wii mote is moved very quickly.
     
  25. enmeii134

    enmeii134

    Joined:
    May 25, 2009
    Posts:
    31
    almar, thank you very much.

    The position I mean is the real position in the world. For example, when I move the remote from left to right without any angle changing, the object in unity can move from left to right. Can this be achieved?

    Looking forward to your examples.

    -Enmeii
     
  26. Almar

    Almar

    Joined:
    May 11, 2009
    Posts:
    87
    To calculate screen coordinates:

    Code (csharp):
    1.  
    2.                 float ir_x = wiimote_getIrX(i);
    3.                 float ir_y = wiimote_getIrY(i);
    4.                
    5.                
    6.                 float temp_x = ( Screen.width / 2) + ir_x * (float) Screen.width / (float)2.0;
    7.                 float temp_y = (((ir_y + (float) 1.0)/ (float)2.0) * (float) Screen.height);
    8.  
    I believe this regards 0,0 as left-top. Unity GUI works from left,bottom as starting point.

    You can convert these screen coordinates to world coordinates using:

    "ScreenToWorldPoint

    Transforms position from screen space into world space."

    Read the manual / forum for some examples.

    I forgot to take a photo of the battery solution, unfortunately though.
     
  27. tylerwilson

    tylerwilson

    Joined:
    Sep 22, 2009
    Posts:
    7
    I hope this does not go against licensing terms in Unity, but I was curious whether there might be a way to use this in Unity Indie, as others asked as well.

    I recall seeing somewhere else in the forums that native plugins cannot be used in Indie, but that external .net assemblies can be. So the solution seems simply enough: re-package the UniWii plugin as a .NET assembly which then calls the 'real' UniWii shared library.

    So I used SharpDevelop on Windows to do just this. I have attached the project folder. The key bits are in the wiimote.cs, which gets built into a WiiMote.dll assembly. This assembly can then be included in your Unity project directly - remembering to put the UniWii.dll somewhere on your system path.

    The calling of the assembly changes the Unity script code slightly of course. A small sample looks like so (taken from a previous example):

    Code (csharp):
    1.  
    2. // Modified UniWiiCheck.cs that uses the .NET assembly instead of the native
    3. // shared library directly. Should work in Unity3D Indie too
    4. //
    5. using UnityEngine;
    6. using System;
    7. using System.Collections;
    8. using System.Runtime.InteropServices;
    9. using WiiMote;
    10.  
    11. public class UniiWiiCheck : MonoBehaviour {
    12.  
    13.     private String display;
    14.    
    15.     void OnGUI() {
    16.         int c = wiimote.count();
    17.         if (c>0) {
    18.             display = "";
    19.             for (int i=0; i<=c-1; i++) {
    20.                 display += "Wiimote " + i + " found!\n";
    21.             }
    22.         }
    23.         else display = "Press the '1' and '2' buttons on your Wii Remote.";
    24.  
    25.         GUI.Label( new Rect(10,Screen.height-100, 500, 100), display);
    26.     }
    27.  
    28.     void Start ()
    29.     {
    30.         wiimote.start();
    31.     }
    32.  
    33.     void OnApplicationQuit() {
    34.         wiimote.stop();
    35.     }
    36. }
    37.  
    Hope this helps.

    Tyler

    PS Note I did not actually run this in Unity3D, but I did create a C# test application, which validates everything is hooked together properly.
     
  28. getamac

    getamac

    Joined:
    Sep 3, 2009
    Posts:
    67
    Hi,
    I'm trying to get a simple head tracking using the Uniwii plugin, and I was wondering if there was a way to get more than a single point with the IR functions ? I didn't see any sample of it so .. Or maybe I don't need more than a single point? Anyway, I'd be grateful for some help :)

    Last question, does the wiimote_isIRenabled( int which ) works for you ? Because when I try to use it as a simple test like :
    if (!wiimote_isIRenabled(n)) wiimote_enableIR(n);
    it freezes my application /: maybe I'm using it the wrong way ?

    Cheers.
     
  29. Apache

    Apache

    Joined:
    Sep 26, 2008
    Posts:
    134
    I guys, I'm trying to use Uniwii to be able to use the Wiiremote for a Windows application but I have a big problem: if the bluetooth hardware is off the
    Code (csharp):
    1. wiimote_start ()
    generates the following exception making Unity crash:
    Code (csharp):
    1. ERROR: inquiry did not start, error 42
    Is there a hint to avoid this issue?

    THANSK !!! :)
     
  30. Almar

    Almar

    Joined:
    May 11, 2009
    Posts:
    87
    Hm, I don't know, I haven't gotten such an error any time. My experience is that Unity simply shows a blank screen most of the time. (When no Bluetooth device is present)

    Anyway, we demonstrated our Wiimote minigames at the Annual "Science day" for children at our company, and it was a great succes. Children couldn't stop playing the simple games ;).

    Today we tried it at the career event (which is an pretty big event), but our Bluetooth sticks seemed to "drown" in bluetooth devices being everywhere (100's). I could connect to the Wiimote, but it would simply not "vibrate" once to confirm it's connection. Not much of a problem, we demonstrated our other games. But I was wondering if anyone has experienced anything like this before?
     
  31. Barbur

    Barbur

    Joined:
    Oct 30, 2009
    Posts:
    160
    Has this plugin something to do with the Unity Wii version or its main objective is to allow using the wiimote and nunchuk on PCs and MACs? I've been reading the UniWii wiki and it does not tells you what do you need to make this work (wiimote, sensor bar, etc) and its main objective.
     
  32. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    No. This has absolutely nothing to do with the official builds of Unity Wii. This is a 3rd party plugin that Rob created to allow Pro users support for Wii controllers.
     
  33. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    431
    Hi,

    Any news of a Wii Balance Board implementation ? this would be so cool...
     
  34. Samosito

    Samosito

    Joined:
    Jul 10, 2009
    Posts:
    7
    Hi everyone

    I'm using UniWii for my project. The plugin is really great.
    I just got a question: when launching the program, Unity blocks if Bluetooth is not activated. Is there any way to check whether bluetooth is activated or not? I searched in unity and .Net/Mono docs, but couldn't find yet.
    It'd be good to activate Wiimote functions only if Bluetooth is running on the computer.

    Thanks
     
  35. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    Can anyone give me an example of how can I get the battery level of the wiimote and how can I use the rumble?
     
  36. c4scroller

    c4scroller

    Joined:
    Sep 16, 2009
    Posts:
    24
    Has anyone managed to get UniWii working with the indie version of Unity? I noted the post earlier with some .cs but there were no files attached even the the author said he was attaching some.

    Greg
     
  37. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    This is a C/C++ plugin and those are only supported in Unity Pro. For reference:

    http://unity3d.com/unity/licenses

    See the section for "C/C++/Object-C Plugins Support" in particular.
     
  38. spg

    spg

    Joined:
    Aug 6, 2009
    Posts:
    79
    Any update on this one? Yaw always returns 0 for me also.
     
  39. c4scroller

    c4scroller

    Joined:
    Sep 16, 2009
    Posts:
    24
    Thank you. Does anyone known of any other wii interface libraries that do work with indie?
     
  40. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    Wiimote only can have Yaw when it has attached the wiimotion plus.
     
  41. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    321
    Does that mean UniWii supports the MotionPlus?
     
  42. rouhee

    rouhee

    Joined:
    Dec 23, 2008
    Posts:
    194
    Damn, last time i tested this, i got it working. Now the WiiMote won't connect properly to the machine (Vista64 with AMD).
    The blue light indicator just keeps blinking. But windows says it is "connected".
    Anyone else got this kind of problem?

    I've tried on several different machines and controllers. Did i miss something? or did the Vista Update (at somepoint) do something funny? :?
     
  43. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    No, it doesn't support wiimotion plus. Hope It could soon.
     
    Last edited: Nov 30, 2010
  44. X-Developer

    X-Developer

    Joined:
    Oct 31, 2009
    Posts:
    162
    To bad I don't have Unity Pro then I could try out your plugin.
     
  45. Simon_Prog

    Simon_Prog

    Joined:
    Dec 3, 2009
    Posts:
    4
    Hello,
    Is it possible to use the plugin directly with javascript instead of C#?

    If not, how can we send information from a C# file to a Javascript file? Because I'm currently working on a Unity project that we started in Javascript.


    EDIT: The solution is very easy. I post it to those who have the same problem.

    Just create a new folder called "Standard Assets" and put the C# file in it. Then put your Javascript wherever you want (but not in this folder), and that's ok.
    This problem is due to the compilation order (the folder "Standard Assets" compile first)
     
  46. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    Simon_Prog yes its posible in fact I making a game based in the wiimote, and I started in javascript. The only thing you have to do is place a script in the plug in folder, that sends static vars to the javascripts that you already have. Hope this can help you
     
  47. samlebr

    samlebr

    Joined:
    Mar 25, 2009
    Posts:
    52
    Just tried the download link (windows) linked on the wiki. But the file seems to have been removed from the server.

    Is there anywhere else I can find the plugin for download/would anyone be kind enough to upload it and throw me a link please?
     
  48. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Hi,

    I'm new in Unity3D, but I make for Blitz3d (my other hobby here : http://www.blitzbasic.com/Community/posts.php?topic=83082 ) a sort of "face webcam tracking" library who sending data via UDP. Is it possible to do the same thing with UniWII for users of version Indie?.

    a) The original UniWII DLL is calling by a Non-GUI (console) application
    b) This application send the data information to Unity via the UDP protocol

    I think it's possible, but i've no time to try this.
    And, maybe this solution works well with the WebPlayer? 8)

    JP

    Sorry for my english. :p

    PS :UDP http://forum.unity3d.com/viewtopic.php?t=36454 or http://forum.unity3d.com/viewtopic.php?t=41407 or http://forum.unity3d.com/viewtopic.php?t=16937

    EDIT : where is the Windows's DLL?
     
  49. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Windows version link updated on the wiki :)
     
  50. Theformand

    Theformand

    Joined:
    Jan 2, 2010
    Posts:
    262
    Anyone fancy converting the WiimoteTestController script to JS?

    Im having some trouble since im only somewhat knowledgeable about JS, im sure others are too. Any initiatives in this direction would be greatly appreciated :wink:
     
unityunity