• 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
0
Question by PlayCreatively · Oct 17, 2016 at 11:54 PM · inputcontrolleraxisinput managerplayers

Read analog stick input without using the Input Manager

I'm making a quick prototype and there is no real reason for having a specific limit of players in the game (at this state) so I want to be able to read every single controller connected to the computer without having to make multiple axis in the Input Manager.

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
0

Answer by YesNoKonrad · Oct 18, 2016 at 12:51 AM

Yes indeed.

To ask for an arbitrary keycode you use the enumeration KeyCode.

The KeyCodes for the joysticks follow all the following formula:

KeyCode.Joystick*XButtonY where you replace X with the joystick number (order is determined by the order they are identified (i.e plugged in) by the computer) and Y with a number. numbers reach from 1 to 19.

hint: The * Behind Joystick is a bug.

for example Input.GetAxis(KeyCode.Joystick2Button1) should return either the vertical or horizontal axis of the left stick when im not mistaken.

Warning: I don't know if GetAxis() actually works with KeyCodes.

  • If yes, this is the way.

  • If no, there is only GetKey(Down/Up) left and that function only returns bool which means you cannot make decent use of the sticks without actually configuring them in the InputManager.

Comment
Add comment · Show 11 · 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 PlayCreatively · Oct 18, 2016 at 01:32 AM 0
Share

No, GetAxis only reads the axis determined in the Input $$anonymous$$anager (as I'm aware). So my only known option is to use Get$$anonymous$$ey but I already knew about that. I was hoping for a solution to get analog input without using the Input $$anonymous$$anager. Thanks anyways.

avatar image YesNoKonrad PlayCreatively · Oct 18, 2016 at 01:37 AM 0
Share

Shame. Well, that is why they work on a new Input class. Can't be done soon enough if you ask me!

avatar image PlayCreatively YesNoKonrad · Oct 18, 2016 at 01:46 AM 0
Share

Oooh, sounds exciting. I shamefully start on new projects all the time, loosing interest in my current projects. Which means that I'm always starting from scratch and wasting allot of needless time on setting up the Input$$anonymous$$anager.

Show more comments
avatar image Naphier · Oct 18, 2016 at 07:16 AM 0
Share

GetAxis will accept a string ("axis 1", etc). What we do to determine all available axes is generate a string (string.format("axis {0}", i)) for i = 1 to 20. Do this inside a try-catch, when the catch happens the previous i is your final available axis on the controller. I believe this is for all the connected controllers, so I'm not sure if there is a way to separate it, but is there is the string is likely "joystick 1 axis 1". This also works for the Input.Get$$anonymous$$eyDown("joystick 1 button 1"). We use the same try-catch method to determine the joystick number connected.

avatar image PlayCreatively Naphier · Oct 18, 2016 at 05:01 PM 0
Share

They all return an error. Joystick1Axis1 and etc doesn't exist.

avatar image Naphier PlayCreatively · Oct 18, 2016 at 05:02 PM 0
Share

It's just "axis 1" and spaces and capitalization is important "joystick 1 button 1"

Show more comments
Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

66 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input for bluetooth controller? 0 Answers

360 Trigger Pressing both Triggers at the same time 1 Answer

The value of Input.GetAxis("Horizontal") gets stuck when Xbox controller is disconnected... 0 Answers

Gamecube Controller joystick axis does not work? 0 Answers

Problems with joystick / controller axes being 1/-1 "way too often" 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges