Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Neurus_Ex · Mar 17, 2015 at 12:10 PM · inputinputmanagerinput.getaxis

Managing input for several players using pads in the same computer.

The "tl;dr" question about input, could be: Which is the best way to manage several players (up to 4), each using its own Xbox 360 controller, in Unity?

The long version follows:

As the tl;dr says, I'm trying to manage 4 players in the same screen. I read some time ago about the input manager that Unity uses, but read somewhere that it was really buggy, and that its better to write your own, so thats what I did.

I have my "inputController" which receives a set of pre-configured keys (originally from keyboard) and asks about Input.GetKeyDown(key), Input.getKeyUp(key) and so. The characters moved along right and everything was nice. Then, I "upgraded" it to read also axis from a joystick (Input.getAxis("AxisName"+playerNumber)). Using a custom set of keys (joystickButton) I managed to get one pad working to move a second character, using 4 buttons, the left thumbstick and the triggers. So, the InputManager has now 4 "custom" axis: 2 for the thumbstick (horizontal and vertical) and the other two for both triggers.

  • My first problem is that I don't know how can I control a second pad plugged in the same computer. For what I've seen here, for the buttons is easy as "joystickButton", where "n" is the number of the player (i.e. "Joystick4Button0"). The real problem comes with the axis. As I'm reading them from the "custom axis" I make in the Input inspector, do I need to set up 4 custom axis for each new player, and make each player "read" the designated axis? can I have several "Inputs", each copy of the other, but with different bindings?

  • The second problem is that what I've seen in the documentation is puzzling me now: It seems that the idea is to allow the player redefine the controls through the "Input" tab on the start menu, but, of course, what I'm doing kind of overrides it completely. Is Unity's standard Input handling reliable enough to be used, should I convert my class to work with it or I'm better handling everything by myself and not paying attention to this module?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Neurus_Ex · Mar 19, 2015 at 08:15 AM

Got an answer on a spanish forum where I asked, so here is what's going on:

  • The InputManager for Unity seems to be something to avoid, except when adding new axes to the game.

  • For each pad, to handle its buttons, you need to call input.JoystickButton (As my previous example, input.Joystick7Button1).

  • Also for each pad, you need to create custom axis. As it (kind of) says here, each thumbstick needs 2 axis (vertical and horizontal), and each trigger needs one axis. This is, for each pad, a total of 6, euh, axii? Each one to be defined individually in the InputManager.

- So, to "answer" my question, from the Input inspector, for the pad n to be read, you need to define a specific axis (i.e. "RightTriggerN"), specify its axis (being a trigger, is 9th axis for right trigger, 10th axis for left trigger, for the thumbsticks would be X, Y, 4th and 5th), then mark on the "Joy Num" dropdown, "Joystick N." For the buttons, would be Input.JoystickNButton

I'll add this nice screenshot to illustrate the bold paragraph: alt text

Here, we have how to access to the InputManager (left), and 4 examples of different axes, from the top left to the lower right, the X axis (left thumbstick) for the first and fourth axes, and both axis for the triggers of the second joystick.


padsnstuff.jpg (208.9 kB)
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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Joystick Axis 9&10 with more than 2 gamepads 0 Answers

Quirk in Input.GetAxis 0 Answers

How do I add a value to anywhere Input.GetAxis("Horizontal") is called? 1 Answer

Input Snap option not returning 0? 0 Answers

input resets after scene change,Held Down Input not responding after scene change. 0 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