Looking-Glass / JoyconLib

Joy-Con library for Unity.
MIT License
467 stars 91 forks source link

How to Use Both Joycons (for different controls) #14

Open Sliver1002 opened 5 years ago

Sliver1002 commented 5 years ago

Hello! Sorry if this is a bit of a noob question, but I'm working on a game where one player uses the left joy-con to control a spaceship, and the other player uses the right to control the turret. I seem to be having issues connecting a second Joy-Con, and was wondering how to do so.

ankylosaure commented 5 years ago

I'm trying to figure this out now too! @Sliver1002 did you ever solve this problem? I'll report back if I find out how this is done.

playfulbacon commented 5 years ago

Hope that helps! @Sliver1002 @ankylosaure

playfulbacon commented 5 years ago

To elaborate on the method I use:

twojoyconsetup

Sliver1002 commented 5 years ago

Thanks! I'll be sure to try it out later!!!

ankylosaure commented 5 years ago

Hey! It seems to reference a script called "VRControllerInputModule" and without it, it's throwing errors. image

Thank you for being so patient!

playfulbacon commented 5 years ago

@ankylosaure My mistake! You can comment out those two lines that are causing the error. I've also updated the script in my fork to exclude them: https://github.com/andyrbacon/JoyconLib/tree/master/Assets/JoyconLib_scripts

SSoutham commented 5 years ago

Hey, @andyrbacon I'm a current game dev student. When I load your scene and connect the JoyConManager.cs to the JoyConManager object's Script section, and connect the JoyConDemo to the cube's Script section I get an error "Failed to load 'Assets/JoyconLib_plugins/win32/hidapi.dll', expected x64 architecture, but was Unknown architecture. You must recompile your plugin for x64 architecture." And another error "DllNotFoundException: hidapi JoyconManager.Awake () (at Assets/JoyconLib_scripts/JoyconManager.cs:48)."

If at all possible a step by step guide would be absolutely amazing. I'm new to Unity so this may take a couple back and forth messages.

UlyssesWu commented 5 years ago

@SSoutham You should set correct platform for your plugin dll. If it's a x86 (win32 / 32-bits) dll, set to x86; if it's x64 (win64 / 64-bits) dll, set to x86_64.

dllimport

playfulbacon commented 5 years ago

@SSoutham I'm not sure what the issue is exactly. But you could make sure there is a folder titled "win64" in the folder "JoyconLib_plugins" with the api .dll found here: https://github.com/Looking-Glass/JoyconLib/blob/master/Assets/JoyconLib_plugins/win64/hidapi.dll

SSoutham commented 5 years ago

Allow me to rephrase:

  1. Am I connecting the correct script to the cube?
  2. After I create a blank object as a child of the JoyCon Manager and link the JoyConController script to it then what?
  3. I have made sure that the api.dll is in that location, it still fails to load, stating that it's an unknown architecture type
  4. I have deleted the win32 and mac folders from the plugins folder and made sure that the remaining 64 file is set to the correct platform
ankylosaure commented 5 years ago

Hey @SSoutham I ran into the DLL problem too, and solved it by starting a fresh project, importing the original unity package file from wormyrocks, then grabbing the new scripts from andyrbacon's modification and following his instructions from there.

SSoutham commented 5 years ago

Absolutely bizarre, but it worked. New Project, fresh import and dragging in the new scripts seemed to do the trick.

maowu commented 5 years ago

have anyone tried 4 joy cons (right x2, left x2)? The JoyconManager can get list j for 4 but the order will be different after re-play. I know we can use enumerate.product_id to detect left or right, but is it any solution to detect each device?

sphaax commented 5 years ago

Facing the same challenge than maowu. Is it possible to detect each device as an independant controller (and not both left and right controllers paired together)?

Meaning, j variable already list the four of them independantly, but input detection (X/Y Stick Axis, Buttons) is totally different from a left/right pair of controllers (held vertically) to an unpaired set of controllers (held horizontally).

Thanks in advance!

maowu commented 5 years ago

Currently, what my solution is list the joy con consoles then set each device with index and isLeft. After my testing, the index is always follow the order you pair the joy con on windows (but it is random on mac). So I think it is a geek way to detect the device for me, but I really still look for if there is any other solution to detect each device like serial number or something else.

Arctel commented 3 years ago

Hey, trying to use this solution and getting this error: Assets\JoyconDemo.cs(20,13): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List' to 'Joycon'. Should I be changing the list to a single Joycon or the single Joycon to a list? Thanks!