- Home /
Question by
dogeguy38 · Jul 28, 2020 at 05:51 PM ·
inputaxisgetkeydown
Method not calling when 2 inputs are pressed
I have a player that can spawn other game objects and uses the horizontal and vertical axis keys to move around in a top down manner. It can spawn objects while moving only if a single movement key is pressed or still. however when two keys are pressed, such as UP and LEFT it does not spawn anything. the only two keys that can be pressed when it does spawn a object is UP, RIGHT.
Here's the code, but i feel it could also be a input problem
//these get the directions of the keys pressed
direction.x = Input.GetAxisRaw("Horizontal");
direction.y = Input.GetAxisRaw("Vertical");
//spawns a object when space is pressed
if (Input.GetKeyDown("space"))
{
SpawnObject();
}
//this part just flips the sprite left or right
Vector3 flipScale = transform.localScale;
if (Input.GetAxisRaw("Horizontal") == 1f)
{
isRight = true;
flipScale.x = -xSize;
}
else if(Input.GetAxisRaw("Horizontal") == -1f)
{
isRight = false;
flipScale.x = xSize;
}
transform.localScale = flipScale;
}
private void FixedUpdate()
{
//this moves the rigidbody2d realative to the keys pressed
rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
}
Comment
I don't see anything here that's obviously blocking you from hitting space. Out of curiosity, what keyboard do you have? I have a vague memory of owning a keyboard that I couldn't jump with in games when I had certain directional buttons pressed.