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?

Hey there,

I think I finnaly found out what’s going on :smiley: 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 How to Easely Switch Action Maps at Runtime in the Unity Input System: Tutorial - YouTube

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

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:
180605-controlscheme.png

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.