2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Are you currently using any acceleration, where a quick tap makes a small move, and a sustained hold quickly ramps up to max speed? \$\endgroup\$ – DMGregory Aug 5 '17 at 13:43
  • \$\begingroup\$ Added code to the question. \$\endgroup\$ – anomaly Aug 5 '17 at 14:05
  • \$\begingroup\$ Acceleration will solve this problem. You don't have any. \$\endgroup\$ – Draco18s Aug 5 '17 at 17:53
  • \$\begingroup\$ 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. \$\endgroup\$ – Neal Davis Aug 7 '17 at 22:15
0
\$\begingroup\$

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;
        }
        rb.AddForce(new Vector2(-Time.deltaTime, 0), ForceMode2D.Force);
        direction = -1;
    }
    else if (Input.GetKey(KeyCode.RightArrow)) {
        if (direction < 0) {
            rb.velocity = Vector2.zero;
        }
        rb.AddForce(new Vector2(Time.deltaTime, 0), ForceMode2D.Force);
        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);
    }
\$\endgroup\$
  • \$\begingroup\$ Don't forget to come back and mark the answer as accepted :) \$\endgroup\$ – Vaillancourt Aug 6 '17 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.