A little bit of help plz with my script :)

Hi everyone, i’m making a multiplayer game that one player move with “WASD keys” and one with “Arrow keys” All my script work perfectly but one thing… i don’t know how to explain it but ill try. Everytime that I press by exemple the “W” with the “Bottom arrow” my two character stop. they block and we have to repress the button to continue. Other example : “A” with “Right arrow”… “D” with “left arrow”… “S” with “up”… as you seen, its always when i press two opposite key in the same time. This is my scripts.

Player 1 :

var speed = 13;
var jumpSpeed = 8.0;
var gravity = 20.0;

private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
    if (grounded) {

if (Input.GetKey("w") || Input.GetKey("s"))
    {
       moveDirection = Vector3(0, 0, Input.GetAxisRaw("Vertical") * speed);   //Axe Z
       moveDirection = transform.TransformDirection(moveDirection);
    }

if (Input.GetKey("a") || Input.GetKey("d"))
    {
       moveDirection = Vector3(Input.GetAxisRaw("Horizontal") * speed, 0, 0);   //Axe X
       moveDirection = transform.TransformDirection(moveDirection);
       
    }
    }

    //Mettre la gravité
    moveDirection.y -= gravity * Time.deltaTime;

    // Bouger le joueur
    var controller : CharacterController = GetComponent(CharacterController);
    var flags = controller.Move(moveDirection * Time.deltaTime);
    grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}

@script RequireComponent(CharacterController)

Player 2:

var objectSpeed = 13;
var gravity = 20.0;
var jumpSpeed = 8.0;

private var moveDir = Vector3.zero;
private var grounded : boolean = false;

function FixedUpdate() {
    if (grounded) {

if (Input.GetKey("up") || Input.GetKey("down"))
    {
       moveDir = Vector3(0, 0, Input.GetAxisRaw("Vertical") * objectSpeed);   //Axe Z
       moveDir = transform.TransformDirection(moveDir);
    }

if (Input.GetKey("left") || Input.GetKey("right"))
    {
       moveDir = Vector3(Input.GetAxisRaw("Horizontal")* objectSpeed, 0, 0);   //Axe X
       moveDir = transform.TransformDirection(moveDir);
    }

}    

    //Mettre la gravité
    moveDir.y -= gravity * Time.deltaTime;

    // Bouger le joueur
    var controller : CharacterController = GetComponent(CharacterController);
    var flags = controller.Move(moveDir * Time.deltaTime);
    grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}

@script RequireComponent(CharacterController)

P.S : My game is a Pac-Man like… but with two players.

I’m afraid you’re running into a problem that has been common to keyboards for many many years now. The last computer I know of that didn’t have this problem was the Amiga 500. It’s a cost cutting measure on the part of keyboard manufacturers.

You can get a pretty good summary of the issue here (Microsoft.com)

The short answer is that keyboards can only detect a certain number of keys at a time. Even very good ones will miss keys in unusual or unexpected combinations.

I’m sorry that this is not an answer as such, but there is no simple or universal answer, other than to try and find key combos that rarely “Ghost” each-other, but even that is no guarantee, as different keyboard manufacturers may vary which combos collide.