Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Local Multiplayer with the new input system

Discussion in 'Input System' started by Marythu, Mar 29, 2021.

  1. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    Hello everybody :)

    I tried to create a local multiplayer mode with the new input system for my game with the great tutorial of samyam. When i try to use one (or multiple) keyboards as input the first player spawns without any problem, but if i use the second input scheme to "spawn" a second player nothing happens and the first player gets controlled. Is there any way for unity to interpret the different inputs as two and not one source?

    Thank you for helping!
     
    big-brain_student and OneToMany like this.
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    Hi,
    Don't think Unity, or any computer makes so big of a difference of which of multiple connected keyboard pressed the wasd-keys, or arrow keys. But I can be wrong.
     
  3. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    So there is no way to create local multiplayer with one keyboard?
     
    Last edited: Mar 30, 2021
  4. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    One way may be to prepare keyboards for each player to use as game controllers. Like glueing all keys but wasd on one keyboard, and all keys but the ijkl on another, and so on.

    (Or I perhaps completely misunderstood the question, if the problem instead was how to control each player with separate sets of keys on a single keyboard?)
     
    Last edited: Mar 30, 2021
  5. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    YES! Its the second one. I probably explained it very poorly. The first one wouldnt be a challenge. I want to create two players with a different keyboard input (like wasd & ijkl), which can be controlled separately. But the problem is everytime i press a key of the second control scheme to spawn a second player nothing happens and the first player follows the instructions from the wasd aswell as the ijkl scheme at the same time. Just like you said my intention is to control each player with separate sets of keys on a single keyboard.
     
    Last edited: Mar 30, 2021
  6. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    How about some checking like:
    Code (CSharp):
    1. if (playerId == 1)
    2. {
    3.    MovePlayer(inputActionVectorWASD);
    4. }
    5. else if (playerId == 2)
    6. {
    7.    MovePlayer(inputActionVectorIJKL);
    8. }
     
  7. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    How do i get the playerID? I used this tutorial btw so get you get a reference (
    )
     
    Last edited: Mar 31, 2021
    Walter_Hulsebos likes this.
  8. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    I believe that person was using the keyboard wasd keys for one player, and a controller for the other player. The ijkl keys has to be added if you want to use one keyboard for both players. Perhaps the local multiplayer system then will assign one scheme for each player. I haven't checked the code, or docs for it.
     
  9. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    Yes, i already did that. My problem starts when i want to spawn my second player using the ijkl scheme, but like i explained already my first player follows the input scheme of wasd and ijkl at the same time and no second player gets created.
     
  10. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    I am having the same issue now. Did you find a solution?
     
  11. Marythu

    Marythu

    Joined:
    Mar 29, 2021
    Posts:
    13
    OneToMany likes this.