I am making a FPS style game and I want my character to be able to run and jump. I have the movement working with WSAD and I have the SPACE bar set to make the character jump. The problem is if I hold down W and then hit the space bar nothing happens or it acts like it was trying to jump but doesn’t.
Can Unity only process one keyboard key at a time?
if (Input.GetKey (KeyCode.W) )
{
if(feetonground ==true) //only allow control if on ground
rigidbody.velocity = transform.forward * speed;
}
if (Input.GetKey (KeyCode.S) )
{
if(feetonground==true)
rigidbody.velocity = transform.forward * -speed;
}
if (Input.GetKey (KeyCode.A) )
{
if(feetonground==true)
rigidbody.velocity = transform.right * -speed;
}
if (Input.GetKey (KeyCode.D))
{
if(feetonground==true)
rigidbody.velocity = transform.right * speed;
}
if (Input.GetKeyDown (KeyCode.Space))
{
if(feetonground==true)
rigidbody.velocity=(transform.up/2 +transform.forward) *jumpheight;
}