You have 2 x float moveX for Vertical and Horizontal. I think there should be moveX and moveY but im not sure.
Anyway, you can just do controller for 2 players with using for first player WSAD and second player arrows. Just check what button is pressed and move player one or two.
How can i do that? I made a movement script for player then i duplicated the player after that i added them to my scene. When i press the “WASD” or Arrow keys, they are moving together. How can i convert vertical or horizontal inputs to keycode? That’s my first project.
Simple way to do this (but im not good in programing so its may be wrong way) is check what button is down. You can do this with Update function, just like that:
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
{
some functionality for rigidbody2d (rb for player 1)
}
if (Input.GetKey(KeyCode.DownArrow))
{
some functionality for rigidbody2d (rb for player 1)
}
if (Input.GetKey(KeyCode.W))
{
some functionality for rigidbody2d (rb for player 2)
}
}
Do public rigidbody2d variables for both players and attach rb components to it for both players. If my way is wrong please somebody correct me.