New input system local multiplayer: move the second player
Hi,
This is my first post here on the forum, please let me know if I break any rules.
I'm currently trying to move from the old input system to the new input system. I have two players on the screen at the same time. One should be controlled by WASD+Spacebar, another by ARROWS+Numpad0.
What I did was to create 2 ActionMaps. One called PlayerOne and the other PlayerTwo: Each player has the correct ActionMap configured on the editor instance:
The problem is: When both of them are present on the same scene, only Player_1 works. Player_2 events aren't even called. Testing, I deleted the Player_2 prefab from the scene and then changed the Player_1 controls to PlayerTwo ActionMap (the one which should control the player two) and surprisingly it works as expected, player_1 is now controlled by ARROWS+Numpad0.
Am I missing something?
Here is the implementation of Player_1 and Player_2:
private Vector2 _iMovement;
private void Update()
{
HandleMovement();
}
private void OnMove(InputValue value)
{
_iMovement = value.Get<Vector2>();
}
private void HandleMovement()
{
var direction = new Vector3(_iMovement.x, _iMovement.y);
transform.Translate(direction * (speed + _speedBonus) * Time.deltaTime);
transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, -4, 0));
if (transform.position.x >= 11.1)
transform.position = new Vector3(-11.1f, transform.position.y, 0);
else if (transform.position.x <= -11.1)
transform.position = new Vector3(11.1f, transform.position.y, 0);
}
Answer by Zoltantan · Jun 16, 2020 at 06:12 PM
@BrunoBelvedere Well, although this won't solve your problem, I experienced a somewhat similar problem. On the pre-version it was working fine but on the latest the second controller won't fire any events.
Anyways you don't need separate ActionMaps. One should be enough, please check this https://www.youtube.com/watch?v=D8nUI88POU8 ( title: New Input System With Local Multiplayer in Unity ).
Also, make sure that you have separate ControlScheme for Keyboard/Controller.
Answer by MrWhiteGorilla · Nov 09, 2020 at 12:55 PM
hello there I am facing the same problem at the moment and I couldn't solve it I just discovered that when you ever add a second player the input for the first player will not send I still I didn't figure it out please could you f you solve this problem to share the solution of it
Hey @$$anonymous$$rWhite$$anonymous$$illa , I'm not working on this project anymore, but if I remember, you cannot use the same input device for both (or more) players at the scene. That is, one should be using the keyboard, other a gamepad or whatever. I'm not really sure if that's a bug or it should really behavior like that. I remember I searched for it at the time and discovered It wasn't possible. What I did was to keep up with the old methods for controlling the players, unfortunately. Please, let me know if you manage to fix this somehow.