Hi, I’m a beginner programmer. I’m making a player rotation input method and I’m having trouble with making a 45 degree rotation by pressing two keys (up and right for example). The trouble is that the gameplay (2d top down game) is sort of timed dexterity thing and it requires only one attempt at rotation, so if the player wants to rotate to 45 and presses up and right at once the program registers either up or right rotation first and only then the 45 degree middle position. I think that I need some kind of very short timer during which the program will check is some other key pressed instantly after and make the rotation and if it is not then it will only rotate according to the first key. I tried several stuff but i can’t make it work.

Thanks in advance for any help.

Here’s an example of my code for rotation without the middle 45 degree position.

```
public void HandleInput()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
}
}
```

You want to exclude each others from the first conditions, like :

```
public void HandleInput()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && !Input.GetKeyDown(KeyCode.RightArrow))
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
}
else if (Input.GetKeyDown(KeyCode.RightArrow) && !Input.GetKeyDown(KeyCode.UpArrow))
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
}
else if (Input.GetKeyDown(KeyCode.RightArrow) && Input.GetKeyDown(KeyCode.UpArrow))
{
// third action
}
}
```

or use a mutual exclusive state (finite state) using an enum

```
public enum STATE {None, Up, Right, UpRight};
private STATE _state;
public void HandleInput()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && !Input.GetKeyDown(KeyCode.RightArrow))
{
_state = STATE.Up;
}
if (Input.GetKeyDown(KeyCode.RightArrow) && !Input.GetKeyDown(KeyCode.UpArrow))
{
_state = STATE.Right;
}
if (Input.GetKeyDown(KeyCode.RightArrow) && Input.GetKeyDown(KeyCode.UpArrow))
{
_state = STATE.UpRight;
}
switch (_state)
{
case STATE.Up :
transform.rotation = Quaternion.Euler (Vector3.Up);
break;
case STATE.Right :
transform.rotation = Quaternion.Euler (Vector3.Right);
break;
case STATE.UpRight :
transform.rotation = Quaternion.Euler (new Vector3 (0, 0, 45));
break;
}
}
```

Just to post a solution to this.

This gets called when a player presses first key.

```
IEnumerator CheckForRightButton()
{
int counter = 0;
bool rotated = false;
//here i check for five frames did the player press another key after the first one
while (counter < 5)
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 45));
rotated = true;
Debug.Log("Up/Right");
yield break;
}
counter++;
yield return null;
}
//if just one key was pressed then this is executed
if (!rotated)
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
Debug.Log("Up");
}
}
```