• 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 barisdincer · May 26 at 02:14 PM · networkinginputkeyboardclientgamepad

Gamepad and keyboard act differently in multiplayer game using Input System

I am working on a multiplayer fighting game where players will move in x and y axis (jump) and will shoot towards each other.

I want to get input both from keyboard & mouse and gamepad (I'm using a PS4 controller at the moment).

I assigned Space key and Gamepad south button (X button as I'm using a PS4 controller) for jumping.

Here is my basic configuration for movement actions:alt text To test the jumping, I start the editor as server and I run 2 standalone instances of the game as clients.

When I test the input with keyboard it works as expected. Every client can control their own player (green in the screenshot below). However, when I test it with gamepad each client can control both players.

The screenshots of keyboard and gamepad inputs respectively: alt text

My code:

 [SerializeField] private Rigidbody _rb;
         [SerializeField] private float jumpSpeed = 8f;
 
         private PlayerInputActions playerInputActions;
 
         private PlayerInputActions PlayerInputActions
         {
             get
             {
                 if (playerInputActions != null)
                 {
                     return playerInputActions;
                 }
                 return playerInputActions = new PlayerInputActions();
             }
         }
 
         public override void OnNetworkSpawn()
         {
             if (!IsLocalPlayer) { return; }
             PlayerInputActions.PlayerMovement.Jump.performed += ctx => PerformJump();
         }
 
         private void OnEnable() => PlayerInputActions.Enable();
         private void OnDisable() => PlayerInputActions.Disable();
 
         private void PerformJump()
         {
             if(!IsLocalPlayer) { return; }
             Vector3 jumpVector = Vector3.up;
             HandleJumpServerRpc(jumpVector);
         }
 
         [ServerRpc]
         private void HandleJumpServerRpc(Vector3 jumpVector)
         {
             _rb.AddForce(jumpVector * jumpSpeed, ForceMode.Impulse);
         }

I am using Netcode for GameObjects as multiplayer library, but I tried the same with Mirror but no luck.

Is this a bug with the Input System?

keyboard-and-gamepad-inputs.png (110.2 kB)
inputsystem.png (42.6 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

216 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 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 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 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

Unity input system only triggers once 2 Answers

How to find out if a button has been released (new input system/gamepad) 0 Answers

Multiple Players on one Computer/Console 5 Answers

Switching between Inputs 1 Answer

No keyboard events detected after any key is held. 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