Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

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

Open
Sliver1002 opened this issue Oct 18, 2018 · 16 comments
Open

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

Sliver1002 opened this issue Oct 18, 2018 · 16 comments

Comments

@Sliver1002
Copy link

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
Copy link

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
Copy link
Contributor

playfulbacon commented Nov 4, 2018

  • Make sure that both Joy-Con are connected to your computer via Bluetooth before running the game.
  • JoyconManager.cs contains a public List of connected Joy-Con called "j". The setup of this list happens on Awake() - that's why it's important to connect before starting the game. You could move the contents of this function and Start() into your own and call it whenever you want to setup the Joy-Con.
  • The Joycon class contains a public bool "isLeft" that you can use to determine which Joy-Con it's referencing.
  • So, one possible solution: Grab the List of connected Joy-Con from JoyconManager.cs and use a bool check to assign the appropriate Joy-Con to whatever controller you're using.

Hope that helps!
@Sliver1002 @ankylosaure

@playfulbacon
Copy link
Contributor

playfulbacon commented Nov 4, 2018

To elaborate on the method I use:

  • I've modified JoyconManager.cs slightly for convenience and created a JoyconController class. You can find them in my fork: https://github.com/andyrbacon/JoyconLib/tree/master/Assets/JoyconLib_scripts
  • The gif below shows how I set them up. You can set the "Joy-Con Type" (Right or Left) in the Inspector for JoyconController, and it will get the correct Joy-Con from JoyconManager.
  • You can then reference the JoyconController to get the Joy-Con you want :)

twojoyconsetup

@Sliver1002
Copy link
Author

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

@ankylosaure
Copy link

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

Thank you for being so patient!

@playfulbacon
Copy link
Contributor

@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
Copy link

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
Copy link

@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
Copy link
Contributor

@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
Copy link

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
Copy link

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
Copy link

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

@maowu
Copy link

maowu commented Jun 20, 2019

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
Copy link

sphaax commented Jun 24, 2019

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
Copy link

maowu commented Jun 24, 2019

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
Copy link

Arctel commented Jun 27, 2021

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants