Simultaneous button press

Hi,

I’m trying to rotate a Pong paddle while moving it up and down using WASD keys but when I press a second key it cancels the original input.

I know there’s bound to be an simple answer somewhere but I haven’t found one that I can figure out (I’m a compete novice)

Thanks for the help

#pragma strict

var UP : KeyCode;
var DOWN : KeyCode;
var RIGHT : KeyCode;
var LEFT : KeyCode;

var SPEED : float = 10;

function Update () {

if (Input.GetKey(UP))
{
	rigidbody2D.velocity.y = SPEED;
}
else if (Input.GetKey(DOWN))
{
	rigidbody2D.velocity.y = SPEED *-1;
}
else if (Input.GetKey(RIGHT))
{
	transform.Rotate(0.0f, 0.0f, -10.0f);
}
else if (Input.GetKey(LEFT))

{
	transform.Rotate(0.0f, 0.0f, 10.0f);
}
else if (Input.GetKey(LEFT)  Input.GetKey(UP))

{
	transform.Rotate(0.0f, 0.0f, 10.0f);
	rigidbody2D.velocity.y = SPEED;

}

else{

	rigidbody2D.velocity.y = 0;

}

}

so you’re saying that when you press both left and right at the same time, that no rotation occurs in what appears to be your tank controls?

Well yeah… you’re saying rotate left 10 degrees per second and rotate right 10 degrees per second at the same time. That would cancel each other out.

What do you expect to happen when you press both? Should it rotate the direction of the most recently pressed? Should it always prefer clock-wise rotation? YOU have to decide what you want it to do…

Though… technically in your code right now as you have it posted. In your code you have a precedence order. Basically you’re saying if pressing up, we move up and do NOTHING else… if we’re not pressing up, then if we’re pressing down, we move down and do NOTHING else… if we’re not moving down, then if we’re pressing right, we rotate right and do NOTHING else… if we’re not rotating right… so on so forth.

What results is that when you press up, you can’t do anything else.

Of course it cancels the input, because you are using a huge if-else branch. Only 1 of the dozen conditions is executed.

You are using a bunch of else if statement, so yeah, only one input will ever take effect because once one ‘if’ statement is true everything ‘else’ is ignored.