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
2
Question by Tuni · May 06, 2014 at 05:27 PM · inputmultiplayerjoystick

Multiple joystick input

Hi,

I want to build a game which supports up to 4 gamepads and keyboard/mouse input. I create the keyboard entries and the gamepad entries for one gamepad in the Input Manager. Is it possible to get the number of the joystick from the Input class while scripting? Is there an better way instead of creating the input entries for each gamepad (4 times + keyboard) in the Input Manager?

I found the Unity-XboxCtrlrInput plugin for Unity. Is there no other way to work with multiple joysticks and Unity in the yearn 2014?

Thanks for reading.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by idbrii · Sep 13, 2014 at 05:59 PM

It's not about the number of joysticks, it's the number of players. If you want to have different inputs for each player, then you need to have different inputs for each player. So you don't need to create another set of controls for the keyboard -- just apply those to player 1. Users can remap them as they see fit. (Of course, this isn't as user-friendly as letting players choose which player is using which device, but it gives them full control over remapping through the launcher.)

Just to make sure we're on the same page, is this the procedure you're following:

Name your inputs after the player and always use numbered joysticks.

  • Axes: Create "P1_Horizontal" and select "Joystick 1" from the "Joy Num" dropdown.

  • Button: Create "P1_Jump" use "joystick 1 button 1".

  • Duplicate these for P2 and use "joystick 2"

In your player controller, add a public variable for the prefix ("P1_") and when calling GetAxes, prepend that prefix:

 public string playerPrefix = "P1_";

 ...
 {
     bool is_jump = Input.GetButtonDown(playerPrefix + "Jump");
     ...
 }

(Or define public variables for all of your inputs so you can pass them directly into GetButtonDown if you're worried about the performance impact of string concatenation.)

When you add players to your scene, you update their playerPrefix variable ("P2_" etc).


Alternatively, the unity-input third-party input manager sounds kinda like what you want. It boasts:

  • Different device configs for different controller types and operating systems Unplug & Plug new controllers while playing, they get initialized automatically with the right configuration Support for up to 4 gamepads with mixed configurations & multiple keyboard configurations * Always get input from the last active device (for singleplayer games)

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 Milo_del_mal · Nov 12, 2014 at 06:51 AM

I am creating a Input detector using the Strategy Pattern at the moment. It detects the joystick input, and to swap between Joysticks you only have to change the class it uses for Input detection.

For example, in the script where you detect the movement you would have:

InputDetector myInput = new Joystick1ControlType(); for player one... or InputDetector myInput = new Joystick2ControlType(); for player two.

However, regardless of which player/joystick they are, their script for jump, would always be:

if(myInput.A_isPressed()) //Do jump

I might have it finished tonight...

Comment
Add comment · Show 1 · 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 Lasorman · Oct 30, 2018 at 02:46 AM 0
Share

Have you finished it yet? $$anonymous$$ost likely answer is yes since this has been 4 years since you posted this.

I really wanted to see what it would look like in script

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

23 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

Related Questions

Input.GetAxis returning nonsensical values for HID Sensor/GameController 0 Answers

How do I call on a player to inherit the input based on the joystick number? 0 Answers

Input.mouse position on GUI Textures 2 Answers

Map iOS joystick to the input manager? 2 Answers

3D Input Issues regarding Two Player Game - When both Left Joysticks get moved, the movement glitches 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