When a 2nd player joins, they are only able to move the character horizontally

I’m using Unity’s new input system (input package) and would like to be able to have it where two controllers can control the same character/player. Is this possible? If so, how would I approach doing this? This may seem like an odd question but I would like to have this functionality for a game I’m working on.

Thanks in advance,

Max

EDIT: I want one player to control horizontal movement while the other player controls vertical movement of the player.

Hi Max,

I’m actually looking for the opposite, as I’m able to control one player with many controllers (using C# Events with the New Input System) :slight_smile:

The steps to get what you want:

  • add an “InputActions” object and map the controllers
  • add an “empty” object and add the component PlayerInputManager to it.
  • make your player object as a Prefab
  • add a “PlayerInput” component to your player prefab
  • to the recently added “PlayerInput” set the InputActions and as behaviour set C# Events
  • create a Script called “PlayerInput”, add it to the PlayerInput object as a component
  • in PlayerInput script, add a code like this such as:
private void Awake()
{
  PlayerInputActions playerInputActions = new PlayerInputActions();
  playerInputActions.Player.jump.performed += OnJump;
  // repeat for other actions (move, climb, etc)
}

private void Jump_performed(InputAction.CallbackContext obj)
{
  // make it jump
}

I hope it helps, otherwise let me know! (Keep in mind that I don’t know if this is a bug or a feature :smile:)
Diego

Hi Diego,

Thank you so much for your response! This is very helpful. I’m already using prefabs, player input, etc., so this should be easy to add in. I’ll tell you if it works once I have time to check.

Thanks again,

Max

1 Like

Hi Diego,

I just realized that what your suggesting is what I already have! I don’t think my question was very clear, I wanted to say that I want to have one player control horizontal movement while the other player controls vertical movement.

Thanks,

Max

Easiest approach would probably be to use UnityEngine.Input and use the Gamepad class to just detect the first two controllers connected. At least for testing purposes, this is what I would start with.

Any ideas for a permanent solution? I was thinking of using the player input manager, would that help me solve the problem?

You essentially just want to be able to assign controllers to 2 separate Input Assets. The same concept for a local co-op game. You’d want your player script to be able to reference these Input Assets. Then you could assign their Inputs to different values in script. Something like

PlayerInputManager - Detects controller input to spawn additional “Players.” You can use their OnJoin and Leave properties however you choose.
PlayerInputManager/Player Prefab - This won’t actually be a player prefab at all, but an empty gameobject with a PlayerInput component.
Controller Script - The script that will reference the newly spawned objects and take their input.

I can’t exactly write out the whole system, but something close to this is what I use for my own multiplayer solutions (With the exception of that I don’t use PlayerInput and PlayerInputManager).

1 Like

Thanks for the reply! I just wanted to mention that the game is local co-op.

Hello everyone! I just wanted to mention that Rin-Dev’s solution worked. Thanks to everyone for trying to get this to work!

Cheers,

Max

1 Like