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
0
Question by JayFitz91 · May 10, 2021 at 05:26 PM · inputmultiplayerevents

Unity Input System local multiplayer

Hi everyone,

I am using Unitys Input System to create a local multiplayer game. I have the current code configured for my inputs which works great for one player, the code below rotates the camera

 void Movement()
     {
         cameraInputMovement = playerActionControls.Camera.OnRotation.ReadValue<Vector2>();
        
         //Multiply the X and Y Axis by the speed the player should move at
         x += cameraInputMovement.x * xSpeed * Time.deltaTime;
         y -= cameraInputMovement.y * ySpeed * Time.deltaTime;
 
         //clamps the Y angle to the limits specified
         y = ClampAngle(y, yMinLimit, yMaxLimit);
 
         //Use the X and Y axis for rotation
         Quaternion rotation = Quaternion.Euler(y, x, 0);

         //Get the distance from the target
         Vector3 negDistance = new Vector3(0, height, -distance);
         Vector3 position = rotation * negDistance + target.position;
 
         transform.rotation = rotation;
         transform.position = position;
     }

The problem is, when I add another player in using the Player Input managers split screen functionality, the camera rotation input controls both players camera rotation. I figured out that I can assign Unity Events to the Player Input component on the player to get around this problem, so I changed my code to the below:

 //This function is assigned on the player input component as a unity event
 public void OnRotate(InputAction.CallbackContext context)
     {
         cameraInputMovement = context.ReadValue<Vector2>();
         Debug.Log("moving");
     }
 
     void Movement()
     {
         //cameraInputMovement = playerActionControls.Camera.OnRotation.ReadValue<Vector2>();
        
         //Multiply the X and Y Axis by the speed the player should move at
         x += cameraInputMovement.x * xSpeed * Time.deltaTime;
         y -= cameraInputMovement.y * ySpeed * Time.deltaTime;
 
         //clamps the Y angle to the limits specified
         y = ClampAngle(y, yMinLimit, yMaxLimit);
 
         //Use the X and Y axis for rotation
         Quaternion rotation = Quaternion.Euler(y, x, 0);
 
         //Get the distance from the target
         Vector3 negDistance = new Vector3(0, height, -distance);
         Vector3 position = rotation * negDistance + target.position;
 
         transform.rotation = rotation;
         transform.position = position;
     }

Unfortunately, with this method, no inputs are picked up at all, not even the Debug Message. It should be noted that the Player Input component is on the player, but this camera script is on the Main Camera, which is a child component of the player, not sure if that matters.

Does anyone know why no inputs are being picked up?

alt text

playerinput.png (47.5 kB)
Comment
Add comment · Show 4
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 The-Peaceful · May 10, 2021 at 07:46 PM 0
Share

Sounds to me like the input settings are somehow configured wrong, if it's not even firing the event. How do the Input settings look like that you've set up for the camera rotation?

avatar image JayFitz91 The-Peaceful · May 10, 2021 at 08:52 PM 0
Share

I've attached a screenshot of the input actions on the player, these input actions work if I directly access the input action in the Update method, it's only when I want to call it from the Unity Events that it's not working. I must be missing something

alt text

avatar image The-Peaceful JayFitz91 · May 11, 2021 at 10:55 AM 0
Share

For some reason the picture can't be loaded :/ . So let's do it this way: I am guessing you are using Delta [Mouse] as the binding path? Do you have any Interactions or Processors applied?

Show more comments

2 Replies

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

Answer by The-Peaceful · May 11, 2021 at 06:07 PM

Hey there,

I think I finnaly found out what's going on :D So by default your 'Player Controls' action map is enabled, but 'OnRotation' is on the 'Camera' action map. Action maps don't invoke events if they are disabled. So either put 'OnRotation' in the 'Player Controls' action map or put a second PlayerInput component on the camera with the Default Map set to 'Camera'. OR if you just need one at a time you could switch around between action maps like show here https://youtu.be/ElqAoS2FEDo?t=417

Think that should do it, let me know if it works :D

Comment
Add comment · Show 5 · 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 JayFitz91 · May 12, 2021 at 01:26 PM 0
Share

Hey,

Thanks a million for all your help so far, what you're saying makes perfect sense. I have changed my setup so that I am only calling from the Player Controls Action Map now. Unfortunately, I am still experiencing the same issue, I am getting no input back in the scene.

I am invoking other Unity Events on the Player Object as well which all work with no issue, it's only the camera one that' causing a problem.

I also tried adding a player input on the camera and used the Camera default map, but the same issue remains. I'm beginning to think that this may be a bug.

I'll continue to troubleshoot it though and if you have any other suggestions in the meantime, I'd be happy to hear them out. Thanks again

alt text

inputs.png (288.5 kB)
avatar image The-Peaceful JayFitz91 · May 12, 2021 at 03:26 PM 0
Share

Ok, that's pretty strange. You could try out the Input Debugger to see if maybe there is no input detected or if there are any other strange things happening there?

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Debugging.html

avatar image JayFitz91 The-Peaceful · May 12, 2021 at 07:43 PM 0
Share

Thanks for that, the delta mouse is definitely being recognized by the debugger. Just as a test, I mapped my OnRotate function to the Movement Action (which works for my movement) and funnily, the camera now rotates when I'm using the WSAD keys.

alt text

So the problem must be with the Delta function, I'm going to try separate out my x and y values into 2 separate functions to check if that works, but I think I'm finally getting somewhere, if I manage to get it working, I'll revert back and accept your answer :)

movementaction.png (283.6 kB)
Show more comments
avatar image
1

Answer by JayFitz91 · May 12, 2021 at 10:29 PM

Hi Everyone,


Sorry for spamming this with my comments, however, I managed to find what was actually causing the issue. In my comments above, I mentioned that after removing and creating the Input Action map with the same Actions, the mouse now worked as expected, however, the issue started occurring again once I configured the Control Scheme.


I then realized that this was happening because I was only configuring the Keyboard in the Control Scheme, so mouse input was being registered as it's own device (which now explains why it was adding another player when I clicked the Fire button)


So in order to resolve my issue, I had to create a control scheme with both Keyboard and Mouse: alt text


After this, my mouse started working as normal again because the Keyboard and Mouse scheme were being recognised as one input.


Hopefully this helps anyone else that has this issue.


controlscheme.png (11.6 kB)
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

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

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Is Unity able to utilize 10 gamepads at once? 2 Answers

Multiplayer Estruture 1 Answer

How do I control which class I'm accessing? 1 Answer

What's the best way of handling multiple controllers/inputs? 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