Search Unity

Wiimote Plugin

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

  1. Ricko

    Ricko

    Joined:
    Dec 9, 2007
    Posts:
    169
    Thank you Rob!!!

    Ricko

    Edit: I had to add more exclamation marks. This is so cool.
     
  2. Loran

    Loran

    Joined:
    Nov 14, 2007
    Posts:
    124
    rob, U rock ;)
     
  3. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Ack. All those buttons should be returning bools. Since a sizeof(bool) = 1 byte, the above will work fine, but it's just one of those embarrassing things I wanted to clean up.
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
  5. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Jonathan: yes, I've been working on a head tracking demo using the plugin. In all my spare time ;)
     
  6. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
  7. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    I'd like to implement Johnny Lee's finger demo but that would require two (or more) IrX and IrY values. Any chance of breaking those out separately in the plugin?

    Thanks

    Flash
     
  8. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Flash -- to do that, I will have to modify the plugin to retrieve the raw IR values. I'll take a look at doing that.
     
  9. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    Okay,

    Before I get into the details, I have a bug or an anomaly, the first time I try to initiate the connection between the wiimote and the computer it doesn't work. I get a wii_count value of 1 but nothing else. I am not getting the rumble in the remote and all of the lights go out. It does this in the demo apps as well (but it completely freezes and requires a relaunch). I have to stop the program in Unity, and start it again then hold the power button down on the Wiimote to reset it, once the second connection is made there are no problems. I get a rumble and a blue light under the "1" appears. Easy to work around but not sure what's going on there.


    --- Edit ---

    Rob has updated the wiki code and it works great

    Flash
     
  10. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    That would be great.
     
  11. MrSweet

    MrSweet

    Joined:
    Jan 19, 2007
    Posts:
    143

    +1


    Thanks for this Rob, been a long wait but worth it :)

    Cheers

    Andy
     
  12. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    Rob,

    I have been successful in creating a crosshair that follows the info on the wiimote's IR source. The IrX value goes from -0.8 to 0.8 and the IrY value goes from -0.7 to 0.7. When I get outside of those ranges, it goes right to -100 and 100. Any idea why it doesn't go all the way to -1 and 1?

    I thought that maybe I was to close to my IR source but that didn't change anything.

    This is easily fixed with some adjustments in the code but it may be something worth looking into.

    Unity is also crashing every other time I hit play, is there anywhere that I can get some data on why its crashing to give you some feedback? I'm still new to Macs (bought one to work in Unity) and I'm not familiar with how to catch any error messages when a program crashes.

    Flash
     
  13. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    To see errors that made things crash, go to Applications/Utilities/Console.app
     
  14. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
  15. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Excellent! Great art too. Did you use the UniWii plugin to make this, or something else?
     
  16. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Awesome! I just want to see it from your perspective, now. :) And to try it at GDC.

    Cheers,
    -Jon
     
  17. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
  18. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    Hey Metervara, any chance up providing a binary of the game you guys created?

    Looks pretty cool

    Flash
     
  19. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I love that you guys went this route for the Nordic Game Jam. It looks extremely fun... although Patrick might be overacting a bit in that video :wink: . I can't wait to experiment with this set up once I'm back in Copenhagen!
     
  20. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    No, actually we used a special build of Unity.

    Unfortunately I think that we can't release anything built with the version we used. I don't even have the project, it only exists on Joe's laptop. I think it might be worthwhile to port it to use the plugin instead and a public version of Unity so we can share the project. Not sure if the plugin provides the necessary ir data to do the headtracking though (tracking of multiple points).

    Always :) It's the performer inside of me that breakes out in these situations.

    /P
     
  21. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I actually thought he was underplaying. Seriously when you get into the action, jump up, crouch and jump sideways, thats where the fun is.
     
  22. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    i checked out the head tracking and wii mote vid. looks amazing. just wondering if the plugin supports data from the nunchuck? would be cool to have a resident evil like game with head tracking!!
     
  23. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    That is so awesome :D

    Not much more needs to be said.
     
  24. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Amazing stuff! We need this Unity, please port it over to the production build and let us get creative (and some exercise) :D
     
  25. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Headtracking works!

    (Edited to add: That is to say, headtracking via UniWii woks. I know the Unity devs added it in their private build, but now everyone can do it with the UniWii plugin.)

    Check out the video here. It's only 10 fps so it's not so great, but I think it gets the idea across:

    http://robterrell.com/UnityHeadtracking01.mov


    I modified the mouselook script, which has some obvious issues with headtracking; the motion your body makes needs to be always-facing-front, whereas mouselook tends to make you rotate your head, and the controller loses sight of the LEDs.

    The "Mic level" indicator in the top left is for firing -- in this game, you'll look at targets and fire at them by yelling "fire!" (Kind of like the movie Firefox. But you have to yell the commands, not just think them. And if you forget your Russian, it still works.)
     
  26. swamp

    swamp

    Joined:
    Feb 17, 2008
    Posts:
    2
    hello all,

    I am trying to use the UniWii plug in and having problems. I have downloaded the plug in and put it in its own folder in >assets>plugins and can not access it correctly. Can someone describe how to use the plug-in step by step on a Mac. I'm just trying to do some mouse look stuff

    This forum is great thats for all of your help
     
  27. Matariki

    Matariki

    Joined:
    Sep 27, 2005
    Posts:
    12
    Hi swamp,
    the best start off is to use bliprob's example c# source and get that going first. You can find it in the wiki. You have to place the c# file in the plugins folder and in unity assign that script to some object (eg empty game object). It should then control an object named "wiiparent" if you haven't changed the name in the script to something else.

    Once you get that going change the script to what ever you desire.

    Cheers
     
  28. swamp

    swamp

    Joined:
    Feb 17, 2008
    Posts:
    2
    Thanks Matariki!

    I have the Wii now working. Any thoughts on integrating the nunchuck with the plug-in? I'm trying to get a hand on how the FPS example works, nunchuck for forward and back movement Wii for mouse looking.

    Thanks
     
  29. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    This is just a code snippet, so you won't be able to copy and paste it, but here's how I made the nunchuck work in the FPS sample. The following is a modification of the standard assets MouseLook script:

    Code (csharp):
    1.  
    2. void Update ()
    3. {
    4.     int c = wiimote_count()-1;
    5.     if (c>=0) {
    6.         float ir_x = wiimote_getIrX(c);
    7.         float ir_y = wiimote_getIrY(c);
    8.         if ( (ir_x != -100)  (ir_y != -100) ) {
    9.                 float temp_x = ((ir_x + .5F) /* / 1.5F */) * (float) Screen.width;
    10.                 float temp_y = /*(float) Screen.height - */(((ir_y + (float) 1.0)/ (float)2.0) * (float) Screen.height);
    11.                 temp_x = Mathf.RoundToInt(temp_x);
    12.                 temp_y = Mathf.RoundToInt(temp_y);
    13.                
    14.                 if (lastIrMouseX == -1) lastIrMouseX = temp_x;
    15.                 if (lastIrMouseY == -1) lastIrMouseY = temp_y;
    16.                
    17.                 rotationX += (temp_x - lastIrMouseX) * sensitivityX;
    18.                 rotationY += (temp_y - lastIrMouseY) * sensitivityY;
    19.                
    20.                 lastIrMouseX = temp_x;
    21.                 lastIrMouseY = temp_y;
    22.    
    23.                 rotationX = ClampAngle (rotationX, minimumX, maximumX);
    24.                 rotationY = ClampAngle (rotationY, minimumY, maximumY);
    25.                
    26.                 nStickX = (int) wiimote_getNunchuckStickX(c);
    27.                 nStickY = (int) wiimote_getNunchuckStickY(c);
    28.                 byte nAccX = wiimote_getNunchuckAccX(c);
    29.                 byte nAccZ = wiimote_getNunchuckAccZ(c);
    30.                
    31.                 //display = "Wiimote " + c + " IR X: " + ir_x + " IR Y: " + ir_y + " " + temp_x + " " + temp_y + " " + lastIrMouseX + " " + lastIrMouseY + " nunchuck: " + nStickX + " " + nStickY + " " + nAccX + " " + nAccZ;
    32.                 display = string.Format("Wiimote {0} IR values: ({1,6:G2}, {2,6:G2}) Maps to screen: ({3,4:G4}, {4,4:G4}) Nunchuck stick: {5,5:G4}, {6,5:G4}", c, ir_x, ir_y, temp_x, temp_y, nStickX, nStickY);
    33.                
    34.                 if ( !float.IsNaN(ir_x)  !float.IsNaN(ir_y) ) {
    35.                 Quaternion xQuaternion = Quaternion.AxisAngle (Vector3.up, Mathf.Deg2Rad * rotationX);
    36.                 Quaternion yQuaternion = Quaternion.AxisAngle (Vector3.left, Mathf.Deg2Rad * rotationY);
    37.                
    38.                 if (axes == RotationAxes.MouseXAndY)
    39.                     transform.localRotation = originalRotation * xQuaternion * yQuaternion;
    40.                 else if (axes == RotationAxes.MouseX)
    41.                     transform.localRotation = originalRotation * xQuaternion;
    42.                 else transform.localRotation = originalRotation * yQuaternion;
    43.                 }
    44.                 if (nStickX != 0) BroadcastMessage("nunchuckDataX", nStickX, SendMessageOptions.DontRequireReceiver);  
    45.                 if (nStickY != 0) BroadcastMessage("nunchuckDataY", nStickY, SendMessageOptions.DontRequireReceiver);  
    46.         }
    47.         if (wiimote_getButtonB(c)==1)
    48.             BroadcastMessage("Fire");
    49.         if (wiimote_getButton1(c)==1)
    50.             BroadcastMessage("SelectFirstWeapon");
    51.         if (wiimote_getButton2(c)==1)
    52.             BroadcastMessage("SelectSecondWeapon");
    53.         if (wiimote_getButtonA(c)==true)
    54.             BroadcastMessage("Jump");
    55.         }
    56.         if (wiimote_getButtonPlus(c)==true) {
    57.             sensitivityX += .1f;
    58.             sensitivityY += .2f;
    59.         }
    60.         if (wiimote_getButtonMinus(c)==true) {
    61.             sensitivityX -= .1f;
    62.             sensitivityY -= .2f;
    63.         }          
    64. }
    65.  
    That uses Broadcast to send the nunchuck data to the FPSWalker script:

    Code (csharp):
    1.  
    2. private var gotNunchuckData : boolean = false;
    3. private var fromNunchuckX : float;
    4. private var fromNunchuckY : float;
    5. private var fromNunchuckJump : boolean;
    6.  
    7. function FixedUpdate() {
    8.     if (grounded) {
    9.         // We are grounded, so recalculate movedirection directly from axes
    10.         if (gotNunchuckData) {
    11.             moveDirection = new Vector3(fromNunchuckX, 0, fromNunchuckY);
    12.             gotNunchuckData = false;
    13.         } else moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    14.         moveDirection = transform.TransformDirection(moveDirection);
    15.         moveDirection *= speed;
    16.        
    17.         if (Input.GetButton ("Jump") || fromNunchuckJump ) {
    18.             moveDirection.y = jumpSpeed;
    19.             fromNunchuckJump = false;
    20.         }
    21.     }
    22.  
    23.     // Apply gravity
    24.     moveDirection.y -= gravity * Time.deltaTime;
    25.    
    26.     // Move the controller
    27.     var controller : CharacterController = GetComponent(CharacterController);
    28.     var flags = controller.Move(moveDirection * Time.deltaTime);
    29.     grounded = (flags  CollisionFlags.CollidedBelow) != 0;
    30. }
    31.  
    32. public function Jump() {
    33.     fromNunchuckJump = true;
    34. }
    35.  
    36. public function nunchuckData( x, y )
    37. {
    38.     fromNunchuckX = (x-128) / 128.0;
    39.     fromNunchuckY = (y-128) / 128.0;
    40.     deadenInput();
    41.     gotNunchuckData = true;
    42. }
    43.  
    44.  
    45. public function nunchuckDataX( x )
    46. {
    47.     fromNunchuckX = (x - 128) / 128.0;
    48.     deadenInput();
    49.     gotNunchuckData = true;
    50. }
    51.  
    52. public function nunchuckDataY( y )
    53. {
    54.     fromNunchuckY = (y-128) / 128.0;
    55.     deadenInput();
    56.     gotNunchuckData = true;
    57. }
    58.  
    And similarly, there are functions in the weapons scripts that get called via Broadcast. You could also check the wiimote separately from each script.
     
  30. theMightyAtom

    theMightyAtom

    Joined:
    Aug 10, 2007
    Posts:
    12
    For those without a Unity license (mine's expired), a Mac, programming skills, or even an extra IR sensor bar, do not despare! It is still possible to play with Unity applications with the Wiimote.
    I made a little demo film featuring the Paradise Island demo in the web player on a PC, and a beginners guide to how it's done...
    http://blog.opensourcery.net/

    Of course it's not the same as writing a game specifically for the Wii and I'll be the first to download the plugin (and Unity) as soon as the right project comes along.
     
  31. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I have updated the UniWii wiki page with a very short and simple script, to help new users get started using the plugin.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class UniWiiCheck : MonoBehaviour {
    7.  
    8.     [DllImport ("UniWii")]
    9.     private static extern void wiimote_start();
    10.  
    11.     [DllImport ("UniWii")]
    12.     private static extern void wiimote_stop();
    13.  
    14.     [DllImport ("UniWii")]
    15.     private static extern int wiimote_count();
    16.  
    17.     private String display;
    18.    
    19.     void OnGUI() {
    20.         int c = wiimote_count();
    21.         if (c>0) {
    22.             display = "";
    23.             for (int i=0; i<=c-1; i++) {
    24.                 display += "Wiimote " + i + " found!\n";
    25.             }
    26.         }
    27.         else display = "Press the '1' and '2' buttons on your Wii Remote.";
    28.  
    29.         GUI.Label( new Rect(10,Screen.height-100, 500, 100), display);
    30.     }
    31.  
    32.     void Start ()
    33.     {
    34.         wiimote_start();
    35.     }
    36.  
    37.     void OnApplicationQuit() {
    38.         wiimote_stop();
    39.     }
    40.  
    41. }
    42.  
     
  32. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Hi everybody,

    Can anyone give me a hint how to make the wiimote work with the 2d platform tutorial?

    This is what I'm after

    - Walking left and right with the nunchuck.

    - To have a pointer onscreen controlled by the wiimote ( like in mario galaxy)

    - Jump with the wiimote acceleration function.

    Any help very much appreciated
     
  33. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Hi bliprob

    thanks for a great plugin, it works perfect and seems very stable.

    I have one question though : is it possible to connect more than one wii remote ?

    The wiki says it supports up to 16 wiimotes, but I can only connect one, is there a magic trick that I should know ?

    / claus
     
  34. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    BJerre,

    I tested the plugin with three (long ago). It's always possible I messed something up in a more recent build. I can test again, but I'll have to raid the kids' room for the wiimotes, and that might result in my hospitalization.

    -- Rob
     
  35. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Rob, did I miss something? Is the HOME button supported? I don't see it in the plugin.
    Thanks,
    Brian
     
  36. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Hi Rob

    I have been playing around with your plugin for a few days now. I said in my last post that the plugin seemed very stable, well that was then. I experience crashes ALL the time, I think I'm over 50 just today. I checked the console and to me it seems that the plugin is causing the problem. This what I get in the console.

    3/15/08 8:22:46 PM Unity[3484] wiimote_start
    3/15/08 8:22:46 PM Unity[3484] uniwii discovery started
    3/15/08 8:22:46 PM [0x0-0x118118].com.unity3d.UnityEditor[3484] Reload assembly time: 0.284690
    3/15/08 8:22:46 PM [0x0-0x118118].com.unity3d.UnityEditor[3484] Mono: successfully reloaded assembly
    3/15/08 8:22:50 PM Unity[3484] uniwii WiiRemoteDiscovered
    3/15/08 8:22:51 PM Unity[3484] could not open L2CAP channel ichan
    3/15/08 8:22:51 PM Unity[3484] could not open L2CAP channel cchan (-536870195)
    3/15/08 8:22:51 PM Unity[3484] uniwii WiiRemoteDiscoveryError: -536870195
    3/15/08 8:22:52 PM Unity[3484] uniwii setForceFeedbackEnabled:YES
    3/15/08 8:23:03 PM Unity[3484] uniwii WiiRemoteDiscoveryError: 188
    3/15/08 8:23:05 PM Unity[3484] wiimote_stop
    3/15/08 8:23:05 PM Unity[3484] Warning: Attempted to stop already-stopped WiiRemoteDiscovery

    I hope you find the time to fix it, because this plugin is really cool.

    / claus
     
  37. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Bjerre -- this may sounds crazy, but is BlueTooth on? It looks like the plugin couldn't open the L2CAP channel, which is most commonly from BlueTooth being turned off.
     
  38. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    yes Bluetooth is on, but that would have been a classic error :D The strange thing is that even when I do get the plugin working I still get the errors in my console. Could it be a problem on my computer ? Or maybe I'm just not using the plugin right. I have included a very simple setup that almost every time makes Unity crash.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Collections;
    5. using System.Runtime.InteropServices;
    6.  
    7. public class UniiWii : MonoBehaviour {
    8.  
    9.     [DllImport ("UniWii")]
    10.     private static extern void wiimote_start();
    11.  
    12.     [DllImport ("UniWii")]
    13.     private static extern void wiimote_stop();
    14.  
    15.     [DllImport ("UniWii")]
    16.     private static extern bool wiimote_available( int which );
    17.  
    18.    
    19.     private String display;
    20.    
    21.     void Start ()
    22.     {
    23.         wiimote_start();
    24.        
    25.     }
    26.  
    27.     void OnApplicationQuit() {
    28.         wiimote_stop();
    29.     }
    30.    
    31.     void OnGUI() {
    32.        
    33.         if(wiimote_available(0)){
    34.             display = "The Wiimote is connected - begin the game";
    35.         }
    36.         else
    37.         {
    38.             display = "Press the connect button";
    39.         }
    40.        
    41.         GUI.Label( new Rect(10, Screen.height-100, 500, 100), display);
    42.     }
    43. }
    44.  
    / claus
     
  39. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    I want to try this plugin, but I don't have a Wii. I was going to buy a wiimote controller or two (far more available than the actual console), but I realized I don't know if that's all I need. Do I need the sensor bar, as well? Are any other connectors required? How does the wiimote connect to the machine? I have a new mac pro, that doesn't have wifi - do I need a wifi nic for it to connect to the wiimote?
     
  40. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    to polytropoi

    - you need bluetooth in your mac
    - you need a sensorbar if you want to do positioning, you can get one with batteries third party. (4gamers work for me)

    Thats all you need
     
  41. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Greetings, I am completely new to plugins, please pardon my ignorance. :oops:

    Does one need pro to use this feature?
     
  42. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Yup, plugins are only supported in Pro...

    Sunny regards,
    Jashan
     
  43. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Alright, I've got my Wiimote working (IT IS AMAZING!!) but I'd like to get the nunchucks working. I have absolutely NO experience programming in C#, and I'm having a hard time. I was wondering if anyone could help. :)

    I have a script which moves a sphere that has the main camera as a child. I'd like to modify this script so that the nunchucks will move the player forward/backward, while the rotation of the Wiimote controls the camera rotation. This is the original movement script:


    Code (csharp):
    1. var f = 20.0;  //force of movement
    2.  
    3. function FixedUpdate () {
    4.    rigidbody.AddRelativeForce (Vector3.forward * Input.GetAxis("Vertical") * f);
    5. }

    Now I THINK this would work as a new movement script, incorporating the Nunchucks:

    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. }
    39.  
    40.  
    My biggest problem is--I can't test it because I'd like to modify the sample code from the wiki (the one that rotates the Wii parent object) to broadcast the nunchuck data to my movement script, but I can't figure out how.

    I would be so grateful if anyone could help!!
     
  44. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    A new build of the UniWii plugin is ready. This build fixes the crashing bugs that were present in the old build (sorry!) and better handles wiimote disconnection. It also supports an unlimited number of wiimotes (the hard-coded limit of 16 was removed). Also, in the old build, eventually the remote discovery process would time out; now it's restarted once it ends. All in all, it should be a solid improvement for anyone using the plugin.

    There's an issue if a wiimote drops out (if that happens, all wiimotes with higher indices have their indices change, which is probably lousy for multiplayer games if a dropout occurs). I'll be working on this one, too, although it will probably include an API change (simply getting the count of connected wiimotes won't tell you enough if someone connects and later drops).

    Download it from http://robterrell.com/UniWii.bundle.zip


    -- Rob
     
  45. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Thanks Rob - you rock. :)
     
  46. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Thank you for the update, sir!

    Has anyone been able to get data from the nunchucks? I can't even figure out how to get display the values with "uniwiicheck" script. :(
     
  47. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Change the innermost loop of wiicheck.cs to:

    Code (csharp):
    1.  
    2. for (int i=0; i<=c-1; i++) {
    3.                 display += "Wiimote " + i + " roll: " + wiimote_getRoll(i) + " pitch: " + wiimote_getPitch(i) + " yaw: " + wiimote_getYaw(i) + " nunStickX: " + wiimote_getNunchuckStickX(i) + " nunStickY: " + wiimote_getNunchuckStickY(i) + "\n";
    4.             }
    5.  
    That will get the yaw, pitch, roll, and nuncuck stick values for all connected wiimotes.
     
  48. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Yes, I've done something similar, but the nunchuck values always read zero for me! Am I doing something wrong?

    Edit: my nunchuck works in the FPS demo, so I know it's hooked up correctly.
     
  49. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    I've got my nunchuck values to display (thanks for the help!), but now I'm trying to broadcast the data to another script but things aren't working. I'm not sure if my problem is the broadcasting script or the other script. Here is a snippet of code, am I broadcasting things correctly?


    Code (csharp):
    1.  
    2. void FixedUpdate () {
    3.         int c = wiimote_count();
    4.         if (c>0) {
    5.             display = "";
    6.             for (int i=0; i<=c-1; i++) {
    7. float NunchuckStickX = wiimote_getNunchuckStickX(i);
    8. float NunchuckStickY = wiimote_getNunchuckStickY(i);
    9.            
    10.                
    11. display += "Wiimote " + i + " accX: " + x + " accY: " + y + " accZ: " + z + " roll: " + roll + " pitch: " + p + " yaw: " + yaw + " IR X: " + ir_x + " IR Y: " + ir_y + "\n" + " nunStickX: " + NunchuckStickY + " nunStickY: " + NunchuckStickX + "\n";
    12.  
    13.  if (NunchuckStickX != 0) BroadcastMessage("nunchuckDataX", NunchuckStickX, SendMessageOptions.DontRequireReceiver);    
    14.  
    15. if (NunchuckStickY != 0) BroadcastMessage("nunchuckDataY", NunchuckStickY, SendMessageOptions.DontRequireReceiver);    
    16.  
    17. }
    18. }
    19. }
    20.                
    21.  
    22.  
    Thanks
     
  50. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    That looks right, so I'd guess the problem is on the receiving end. Can you post that code?