Unity Community


Page 1 of 2 12 LastLast
Results 1 to 20 of 35

  1. Location
    France
    Posts
    22

    XInput.NET - full support for Xbox 360 Controller (Windows)

    Hello,

    We developed this for a project we are currently making in our school. I hope you will find it useful, it became a must for us mostly because we will need vibrations.

    It's a plugin which makes available the XInput functions of Windows in an API similar to what you can find in XNA.

    I updated the Wiki page for Extensions and you can find more information about it here : http://speps.fr/xinputdotnet

    Cheers,
    Remi Gillig.

  2. m50 m50 is offline

    Location
    Texas
    Posts
    20
    I tested it out, and i love it! i just had one problem, and that was that the DLL's given in the Unity project were broken, so i had to download your source code and rebuild the DLL's. Other than that, it worked great. I couldn't figure out how to make it so that: "Oh, this camera is controlled by controller 1, this by controller 2, blah blah blah" without making seperate scripts for each, but oh well. Still, was great to see a more advanced xbox controller functionality! Also great to see an PC only plugin for unity for once (and finally!) instead of Mac only ones (grrr!).


  3. Location
    France
    Posts
    22
    It seemed to work for me and for a friend as well. I'm glad that you managed to sort it out yourself. Thanks for the feedback!


  4. Posts
    106
    Thanks for this! Hopefully with the next release of Unity there will be full built-in support for the X-Box controller, but this will be nice to use in the meantime.


  5. Location
    France
    Posts
    22
    Quote Originally Posted by m50
    I tested it out, and i love it! i just had one problem, and that was that the DLL's given in the Unity project were broken, so i had to download your source code and rebuild the DLL's. Other than that, it worked great. I couldn't figure out how to make it so that: "Oh, this camera is controlled by controller 1, this by controller 2, blah blah blah" without making seperate scripts for each, but oh well. Still, was great to see a more advanced xbox controller functionality! Also great to see an PC only plugin for unity for once (and finally!) instead of Mac only ones (grrr!).
    Actually, the binaries on my website were Debug versions, not working on systems without Visual Studio 2008 installed. My mistake, it should be OK now, I updated the links on my website.
    http://speps.fr - video games programmer
    http://puddle-game.com - Puddle (IGF 2010 Student Showcase Winner)
    http://paperplane-game.com - PaperPlane (IGF 2011 Student Showcase Winner, Unity 2.6)
    http://speps.fr/xinputdotnet - XInput.NET, Xbox 360 Controller support for Unity3D


  6. Location
    Sooke
    Posts
    3,218
    It would be sweet if you could also get it working for mac!
    -Insert quote here
    ---Famous Person


  7. Location
    France
    Posts
    22
    Unfortunately, this plugin relies on DirectX and thus can't work on Mac. Sorry, you'll have to head towards custom drivers for Mac.
    http://speps.fr - video games programmer
    http://puddle-game.com - Puddle (IGF 2010 Student Showcase Winner)
    http://paperplane-game.com - PaperPlane (IGF 2011 Student Showcase Winner, Unity 2.6)
    http://speps.fr/xinputdotnet - XInput.NET, Xbox 360 Controller support for Unity3D


  8. Location
    Sooke
    Posts
    3,218
    Aww, oh well.

    I don't personally have a mac, I just love cross-compatibility.

    Good job.
    -Insert quote here
    ---Famous Person


  9. Location
    Vancouver
    Posts
    9
    Has anyone figured out how to use one script that assigns more than one controller? Currently I have two players using the same script, but the script assigns PlayerIndex.One to both controllers. I've tried setting a boolean to change a singe PlayerIndex class to either One or Two (considering I only need 2 players.) then checking the state of only that GamePad.

    My eventual goal is to check the state of two gamepads, if any of them are disconnected, a message will pop up. If one GamePad gets input it will move it's corresponding GameObject. This worked with Joystick[x]Button[x] but I can't figure out a similar route using this plugin.


  10. Posts
    106
    I don't have another controller handy, but at the barebones I believe you need something like the following:

    Code:  
    1. GamePadState Player1State;
    2. GamePadState Player2State;
    3.  
    4. PlayerIndex Player1Index = (PlayerIndex)0;
    5. PlayerIndex Player2Index = (PlayerIndex)1;
    6.  
    7. ...
    8.  
    9. Player1State = GamePad.GetState(Player1Index);
    10. Player2State = GamePad.GetState(Player2Index);

    Then check the buttons for each player's controller using their specific GamePadState and handle accordingly.


  11. Location
    Vancouver
    Posts
    9
    I guess I should have said the script was being applied to two different game objects, but I just turned it into a boolean to fix that. I've reworked the default input loop a bit but am still getting an error somewhere.

    It's not even a good error... I keep getting "expected ;" back, which I assume just means Unity can't think of anything better.

    Code:  
    1. if (bFirstPlayer)
    2.         {
    3.             iPlayerNumber = 0;
    4.             setPlayerIndex = PlayerIndex.One;
    5.             //sVertical = "Vertical";
    6.             //sHorizontal = "Horizontal";
    7.         }
    8.         else
    9.         {
    10.             iPlayerNumber = 1;
    11.             setPlayerIndex = PlayerIndex.Two;
    12.             //sVertical = "Vertical2";
    13.             //sHorizontal = "Horizontal2";
    14.         }
    15.  
    16. ...
    17.  
    18. if (!playerIndexSet || !prevState.IsConnected)
    19.         {
    20.            
    21.             PlayerIndex testPlayerIndex = PlayerIndex.One;
    22.             GamePadState testState = GamePad.GetState(testPlayerIndex);
    23.             for (int i; i < 4; i++; testPlayerIndex++)
    24.             {
    25.                 if (testState.IsConnected)
    26.                 {
    27.                        
    28.                     if (testPlayerIndex == setPlayerIndex)
    29.                     {
    30.                         Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
    31.                         playerIndex = testPlayerIndex;
    32.                         bPlayerIndexSet = true;
    33.                     }
    34.                     else
    35.                     {
    36.                         bPlayerIndexSet = false;
    37.                         Debug.Log("WHAAAAT");
    38.                     }
    39.                 }
    40.        
    41.             }
    42.         }

    The error is apparently in the for loop, though doubtful.


  12. Posts
    106
    Ok, yea if you've got them on different objects each with the script than that could work.

    The error is this incorrect for loop:

    Code:  
    1. for (int i; i < 4; i++; testPlayerIndex++)


  13. Location
    Vancouver
    Posts
    9
    Thanks, I fixed the for loop and a few other errors that popped up later. After fixing everything it was still recognizing both controllers as player one, but I figured out why. Turns out one of my controllers was the wrong kind (XBCD or something), once I plugged in a different XBox controller it all worked fine.


  14. Location
    Vancouver
    Posts
    9
    Hello again, same project, different question.

    I've hit a point where running a check on the GamePad state every frame, and in every script that requires input, is getting a little expensive.

    I've attempted to move the pad check into one script and just referencing it from each of the other scripts. At first I assumed that once the pads were assigned I could simply do (state = GamePad.GetState(One)) (or Two) and it would recognize the controller... this did not happen.

    I've now decided to create a function that returns the state and within each of the other scripts do something like (state = (Find("MainCamera").GetComponent("ControllerConnec t") as ControllerConnect).RunCheck(One or Two)) but I'm not sure what to make the function. I know void doesn't work, and I've tried GamePad ControllerConnect() though that didn't work.

    Does anyone know either how to make a function like that work or a simpler way.

    Thanks


  15. Posts
    1

    getbutton

    Awesome plugin, works great. Except there is a quirky issue with calling Input.GetButtonDown and Up. they don't seem to work when using an input coming from the controller. I can't just use Input.GetButton because it makes my script perpetually execute when I only want it to once. Does anybody know what's going on with it or how to write a custom GetButtonDown script?


  16. Posts
    33
    I can't figure out everything in the state structure. I just tried

    Code:  
    1. m_yPos = m_gamePad.state.ThumbSticks.Right.y;

    after hunting through pages of poorly indexed Microsoft documentation. But I get an access violation.

    How do I actually read the sticks using XInput?
    Almo
    Programmer
    GRIP


  17. Posts
    40
    Hey.
    Is any way of making it work in the WebPlayer ?

    Thanks for the plugin !


  18. Location
    Zürich, Switzerland
    Posts
    26,572
    No, low level and system access is not possible in the webplayer


  19. Location
    Witney, UK
    Posts
    2,460
    NOw I'm really sorry to necropost, but can we have a JS version of this please? I have tried and tried and tried to get it working in JS, and just can't. I don't want to keep routing through another script in another language just to get inputs from the controller.
    http://fishman92.carbonmade.com/ Portfolio
    @fishman92
    Need anything done? Great rates and speedy service. Contact me on skype @fishman.92.


  20. Location
    Leeds, UK
    Posts
    2,060
    This is the Javascript version I use, modified a bit from the regular C one (so I can simplify the code when referencing the pad state - i.e. if (XInput.buttonA) {}, but it should be simple enough to edit back.

    Code:  
    1. #pragma strict
    2.  
    3. import XInputDotNetPure;
    4.  
    5. var playerIndexSet : boolean = false;
    6. static var playerIndex : PlayerIndex;
    7. static var state : GamePadState;
    8.  
    9. // Static variables for
    10. static var h1 : float = 0.0;
    11. static var v1 : float = 0.0;
    12.    
    13. static var h2 : float = 0.0;
    14. static var v2 : float = 0.0;
    15.    
    16. static var buttonA : boolean = false;
    17. static var buttonB : boolean = false;
    18. static var buttonX : boolean = false;
    19. static var buttonY : boolean = false;
    20.    
    21. static var dpadUp : boolean = false;
    22. static var dpadDown : boolean = false;
    23. static var dpadLeft : boolean = false;
    24. static var dpadRight : boolean = false;
    25.    
    26. static var buttonStart : boolean = false;
    27. static var buttonBack : boolean = false;
    28.    
    29. static var shoulderL : boolean = false;
    30. static var shoulderR : boolean = false;
    31.    
    32. static var stickL : boolean = false;
    33. static var stickR : boolean = false;
    34.    
    35. static var triggerL : float = 0.0;
    36. static var triggerR : float = 0.0;
    37.  
    38. function Update () {
    39.     // Find a PlayerIndex, for a single player game
    40.     if ( !playerIndexSet ) {
    41.         for ( var i : int = 0; i < 4; ++i ) {
    42.             var testPlayerIndex : PlayerIndex;
    43.             switch ( i ) {
    44.                 case 0:
    45.                     testPlayerIndex = PlayerIndex.One;
    46.                     break;
    47.                 case 1:
    48.                     testPlayerIndex = PlayerIndex.Two;
    49.                     break;
    50.                 case 2:
    51.                     testPlayerIndex = PlayerIndex.Three;
    52.                     break;
    53.                 case 3:
    54.                     testPlayerIndex = PlayerIndex.Four;
    55.                     break;
    56.             }
    57.            
    58.             var testState : GamePadState = GamePad.GetState ( testPlayerIndex );
    59.             if ( testState.IsConnected ) {
    60.                 Debug.Log ( String.Format ( "GamePad found {0}", testPlayerIndex ) );
    61.                 playerIndex = testPlayerIndex;
    62.                 playerIndexSet = true;
    63.             }
    64.         }
    65.     }
    66.  
    67.     state = GamePad.GetState ( playerIndex );
    68.  
    69.     h1 = state.ThumbSticks.Left.X;
    70.     v1 = state.ThumbSticks.Left.Y;
    71.    
    72.     h2 = state.ThumbSticks.Right.X;
    73.     v2 = state.ThumbSticks.Right.Y;
    74.    
    75.     buttonA = ( state.Buttons.A == ButtonState.Pressed );
    76.     buttonB = ( state.Buttons.B == ButtonState.Pressed );
    77.     buttonX = ( state.Buttons.X == ButtonState.Pressed );
    78.     buttonY = ( state.Buttons.Y == ButtonState.Pressed );
    79.    
    80.     dpadUp = ( state.DPad.Up == ButtonState.Pressed );
    81.     dpadDown = ( state.DPad.Down == ButtonState.Pressed );
    82.     dpadLeft = ( state.DPad.Left == ButtonState.Pressed );
    83.     dpadRight = ( state.DPad.Right == ButtonState.Pressed );
    84.    
    85.     buttonStart = ( state.Buttons.Start == ButtonState.Pressed );
    86.     buttonBack = ( state.Buttons.Back == ButtonState.Pressed );
    87.    
    88.     shoulderL = ( state.Buttons.LeftShoulder == ButtonState.Pressed );
    89.     shoulderR = ( state.Buttons.RightShoulder == ButtonState.Pressed );
    90.    
    91.     stickL = ( state.Buttons.LeftStick == ButtonState.Pressed );
    92.     stickR = ( state.Buttons.RightStick == ButtonState.Pressed );
    93.    
    94.     triggerL = state.Triggers.Left;
    95.     triggerR = state.Triggers.Right;
    96. }
    97.  
    98. static function padVibration ( playerIndex : PlayerIndex, big : float, small : float ) {
    99.     GamePad.SetVibration ( playerIndex, big, small );
    100. }
    101.  
    102. static function stopPadVibration ( playerIndex : PlayerIndex ) {
    103.     GamePad.SetVibration( playerIndex, 0, 0 );
    104. }
    Last edited by Farfarer; 07-27-2011 at 04:27 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •