# How to handle keyboard controls in Arkanoid game

I'm making simple Arkanoid clone in Unity with both keyboard and mouse controls available. When I gave it to my colleagues to test one complain was that keyboard controls are not precise enough,. The problem is that I don't really know how to find a balance between two factors:

• If I make paddle speed too high then it lacks precision to position it just right to make ball go to the last few blocks.
• If I make paddle speed too slow then it's going to be difficult to reach ball in time.

I thought about it and I don't recall any version of arkanoid that solved that problem. Currently I have 3 ideas:

1. Make two (or more) keys to go in each direction. One will go faster and another slower.
2. Instead of making multiple buttons lets allow player to change speed of paddle during the game. Probably by entering number from 0-9 on keyboard.
3. Just leave it like it is now. Other control schemes are not intuitive enough.

Does anyone have any experience with this? Which approach is the most reasonable?

Edit: Code I'm using:

    Vector3 pz = transform.position;
pz.y = y;
pz.z = 0;
if (Input.GetKey(KeyCode.LeftArrow)) {
pz.x -= Time.deltaTime * KEYBOARD_SPEED_MULTIP;
}
if (Input.GetKey(KeyCode.RightArrow)) {
pz.x += Time.deltaTime * KEYBOARD_SPEED_MULTIP;
}
pz.x = Mathf.Clamp(pz.x, -60, 60);
rb.MovePosition(pz);


I simply move paddle by constant speed which includes timedelta. And then I clamp position to screen.

• Are you currently using any acceleration, where a quick tap makes a small move, and a sustained hold quickly ramps up to max speed? Commented Aug 5, 2017 at 13:43
• Added code to the question. Commented Aug 5, 2017 at 14:05
• Acceleration will solve this problem. You don't have any. Commented Aug 5, 2017 at 17:53
• 4. Have a third button that is the "slow" button. When "slow" key is held down, the paddle moves at half speed, when released, paddle moves at full speed. It's just like your two right and two left buttons, but only has three instead of four buttons and allows the user to keep his fingers on the same left and right buttons regardless of the speed. Commented Aug 7, 2017 at 22:15

Since 2 people commented right answer, but none of them has posted response I'm going to respond to my own question.

Adding acceleration seems to be right option. Controls are still not that good as mouse, but I don't think that it can be made significantly better without mouse or touch screen.

I changed rigidbody type to dynamic and removed multiplier constant because I used mass instead. I also added additional code to clamp position and assure that paddle only has inertia when player is holding button.

Result code looks like this:

    if (Input.GetKey(KeyCode.LeftArrow)) {
if (direction > 0) {
rb.velocity = Vector2.zero;
}
direction = -1;
}
else if (Input.GetKey(KeyCode.RightArrow)) {
if (direction < 0) {
rb.velocity = Vector2.zero;
}
direction = 1;
}
else
{
rb.velocity = Vector2.zero;
direction = 0;
}
Vector3 pz = transform.position;
if (Mathf.Abs(pz.x) > 60) {
pz.x = Mathf.Clamp(pz.x, -60, 60);
rb.MovePosition(pz);
}

• Don't forget to come back and mark the answer as accepted :) Commented Aug 6, 2017 at 12:02