Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by parthpatelec · Jul 24, 2015 at 09:02 AM · joystickjoysticks

Two Joystick controller not working together

alt text

![alt text][2]

Here is my script for mobilejoystick object:

 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnitySampleAssets.CrossPlatformInput;
 
 public class JoystickController : MonoBehaviour , IPointerUpHandler , IPointerDownHandler , IDragHandler {
     
     public int MovementRange = 100;
     
     public enum AxisOption
     {                                                                         
         Both,                                                                   // Use both
         OnlyHorizontal,                                                         // Only horizontal
         OnlyVertical                                                            // Only vertical
     }
     
     public AxisOption axesToUse = AxisOption.Both;   // The options for the axes that the still will use
     public string horizontalAxisName = "Horizontal";// The name given to the horizontal axis for the cross platform input
     public string verticalAxisName = "Vertical";    // The name given to the vertical axis for the cross platform input 
     
     private Vector3 startPos;
     private bool useX;                                                          // Toggle for using the x axis
     private bool useY;                                                          // Toggle for using the Y axis
     private CrossPlatformInputManager.VirtualAxis horizontalVirtualAxis;               // Reference to the joystick in the cross platform input
     private CrossPlatformInputManager.VirtualAxis verticalVirtualAxis;                 // Reference to the joystick in the cross platform input
 
     private bool moving;
 
     void Start () {
         
         startPos = transform.position;
         CreateVirtualAxes ();
     }
     
     private void UpdateVirtualAxes (Vector3 value) {
         
         var delta = startPos - value;
         delta.y = -delta.y;
         delta /= MovementRange;
         if(useX)
             horizontalVirtualAxis.Update (-delta.x);
         
         if(useY)
             verticalVirtualAxis.Update (delta.y);
         
     }
     
     private void CreateVirtualAxes()
     {
         // set axes to use
         useX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
         useY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
         
         // create new axes based on axes to use
         if (useX)
             horizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
         if (useY)
             verticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
     }
     
     
     public  void OnDrag(PointerEventData data)
     {    
             Vector3 newPos = Vector3.zero;
             
             if (useX) {
                 int delta = (int) (data.position.x - startPos.x);
                 newPos.x = delta;
             }
             
             if (useY)
             {
                 int delta = (int)(data.position.y - startPos.y);
                 newPos.y = delta;
             }
             
             transform.position = Vector3.ClampMagnitude( new Vector3(newPos.x , newPos.y , newPos.z), MovementRange) + startPos;
             UpdateVirtualAxes (transform.position);
 
     }
     
     
     public  void OnPointerUp(PointerEventData data)
     {
         transform.position = startPos;
         UpdateVirtualAxes (startPos);
 
 //        moving = false;
     }
     
     
     public  void OnPointerDown (PointerEventData data) 
     {
 //        Debug.Log ("moveDown");
 //        moving = true;
     }
     
     void OnDisable () 
     {
             // remove the joysticks from the cross platform input
             if (useX)
             {
                 horizontalVirtualAxis.Remove();
             }
             if (useY)
             {
                 verticalVirtualAxis.Remove();
             }
     }
 }


In this mobilejoystick object has horizontalAxisName = "Horizontal", and verticalAxisName = "Vertical",which is for move control of left side joystick.

on other side at right,mobilejoystick1 object has horizontalAxisName = "HorizontalLook", and verticalAxisName = "VerticalLook",which is for move control of left side joystick.

otherwise both have same script except this changes of above.....

i have two joystick controller for mobile game. In that controller-1 is for movement of character and controller-2 is for rotation of same character. But the problem is that if i touch 1st controller then 2nd will not work at same time.So either first or second work at a time.

will you please help me out?????

2.png (276.1 kB)
joystick.png (174.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by seanrod · Feb 26, 2016 at 05:17 PM

Were you able to figure out how to get the joystick to work together?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bdilloughery_mvla · Mar 09, 2020 at 05:39 PM

Also running into the same problem.

I can plug in multiple different USB controllers, and on each one a single joystick will be detected (either Joystick #1 or #2 depending on controller and setup). The second joystick is never detected.

Is there a reason or a fix for this?

Cheers, Brendan

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by PattiBriggs · Mar 12, 2020 at 10:17 AM

facing same problem I can plug in multiple different USB controllers, and on each mcdonalds survey code one a single joystick will be detected. The second joystick is never detected. i have two joystick controller for mobile game.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Movement w/ Both Joysticks 0 Answers

Not reading joysticks on the Nintendo switch joycon 0 Answers

Joystick isn't responding? 0 Answers

Windows Store app - Joystick not working 0 Answers

PS4 controller right analog stick issue 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges