3
\$\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\$
4
  • \$\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
    Commented Aug 5, 2017 at 13:43
  • \$\begingroup\$ Added code to the question. \$\endgroup\$
    – anomaly
    Commented Aug 5, 2017 at 14:05
  • \$\begingroup\$ Acceleration will solve this problem. You don't have any. \$\endgroup\$ Commented Aug 5, 2017 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
    Commented Aug 7, 2017 at 22:15

1 Answer 1

1
\$\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\$
1
  • 1
    \$\begingroup\$ Don't forget to come back and mark the answer as accepted :) \$\endgroup\$
    – Vaillancourt
    Commented Aug 6, 2017 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .