Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by knoggly · Mar 01, 2010 at 12:41 PM · inputmousekeyboardinputmanagergamepad

Multiple Players on one Computer/Console

Hello,

I'm developing a game where it is possible for players (up to 4) to play simultaniously on one Computer/Console. Now I want the Input to be customizable, so that for example Player1 can choose the mouse as Input, Player2 the keyboard and Player3 an attached gamepad. The Input should be chooseable within the game, not only on startup.

What would be a good solution for this? Is it possible to use the InputManager for this task or have I to code this manually?

regards

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

5 Replies

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

Answer by knoggly · Mar 01, 2010 at 02:52 PM

Thanks for your answers, perhaps one point was not clearly state by me. I don't want the players to choose the keys and buttons. I'm totally fine with defining them myself. But I want to have a defined set of "controllers" the players can choose of (eg. Keyboard1 -> WASD-Keys, Keyboard2 -> UP/DOWN/LEFT/RIGHT-Keys). My problem is connecting the defined Axis in the InputManager to my player-logic, where I have to descide if the current Input was meant for the player.

something like

if(playerNum==1)
{
  value=Input.GetAxis("Player1 left/right");
}
else if(playerNum==2)
{
  value=Input.GetAxis("Player2 left/right");
}

seems quite unelegant for me, but maybe thats the way to go

cheers knoggly

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
1

Answer by jonas-echterhoff · Mar 01, 2010 at 02:20 PM

For the best flexibility, you would write your own Input wrapper, which you can configure. Then you'd have functions like this

bool GetKeyDown(KeyEnum key)
{
    return Input.GetKeyDown(m_Mapping[(int)key]);
}

,which wrap to Input manager functions using a key mapping, which maps your enums to KeyCodes. Then you could make a dialog where you handle Event.KeyDown type events, and assign the key codes to your mapping like this:

void AssignKeyFromEvent(KeyEnum key)
{
    if (Event.current.type == EventType.KeyDown)
        m_Mapping[(int)key] = Event.current.keyCode;
}

where m_Mapping is an array which maps from your enum to key codes. You can do something similar for axes.

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 Ashkan_gc · Mar 01, 2010 at 02:21 PM

there is not any built in feature for what you want. input manager just can customize those inputs that use GetAxis. so if you don't want to use that and want more than 2 players you need to code that yourself. simply when you want to use functions like GetButtonDown as argument send fire1p1 or fire1p3 for fire1 button of player 1 or 3. then in your game set those variables to what you want. input parameters are enums (simple numbers) that you can set to variables easily. you can create a manager object for controls that don't destroy in scene loads or just use static classes.

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 Kethis Celebes · Mar 01, 2010 at 07:54 PM

Since they have answered your question, let me give you a warning:

Most keyboards have a certain number of channels that they can recognize the state of at a time (8 is standard I hear). This means that no more than 8 buttons can be recognized at the same time, and if two buttons are on the same channel then they can not be read at the same time. Surely at some point youve played a game where left, up, and right worked, up+right worked but up+left did not, for example.

This is a hardware problem and there is no work around except to A) change control schemes B) change keyboards and pray (I have a number of Dell keyboards at my job's computer lab, and not all of them present with the same 'impossible pairs').

Note that some keyboards (like my Logitech G15) do not have/minimize this problem, because they have more channels (and thus less keys per channel).

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 knoggly · Mar 04, 2010 at 05:25 PM 0
Share

Thanks for your hint

avatar image
0

Answer by FuzzyQuills · Dec 22, 2013 at 02:23 AM

Here's something you can do: if you are going to use gamepads for this, then simply set the "Get motion on all joysticks" var in the axis settings to read "Joystick (playernumber)" and so on. Just something to help, that's all.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GetAxisRaw("Mouse X") not even close to manual mouse movement 0 Answers

Unity input system only triggers once 2 Answers

Gamepad and keyboard act differently in multiplayer game using Input System 0 Answers

How to calculate mouse and game pad input together? 1 Answer

Mapping multiple controllers 1 Answer


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