Block Breaker Gamepad

So I have been working on making block breaker a game we can play with a gamepad instead of a mouse.
Here’s what I have tried sofar:

  1. Buying a UI virtual mouse from the asset store but that caused a lot of problems.
  2. Took the movement code from Laser Defender 2018 & put it on the paddle. But I have not been able to limit the Y axis.
  3. Tried to edit codes that work for similar games but got nowhere.
    I"ll paste the code for #2 because I do think it’s my best option.
    [SerializeField] float padding = 1f;

    //public static Player instance;
    float xMin;
    float xMax;
    float yMin;
    float yMax;

    // Use this for initialization
    void Start()

    // Update is called once per frame
    void Update()

    private void Move()
        var deltaX = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
        var deltaY = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

        var newXPos = Mathf.Clamp(transform.position.x + deltaX, xMin, xMax);
        var newYPos = Mathf.Clamp(transform.position.y + deltaY, yMin, yMax);
        transform.position = new Vector2(newXPos, newYPos);

    private void SetUpMoveBoundaries()
        Camera gameCamera = Camera.main;
        xMin = gameCamera.ViewportToWorldPoint(new Vector3(0, 0, 0)).x + padding;
        xMax = gameCamera.ViewportToWorldPoint(new Vector3(1, 0, 0)).x - padding;
        yMin = gameCamera.ViewportToWorldPoint(new Vector3(0, 0, 0)).y + padding;
        yMax = gameCamera.ViewportToWorldPoint(new Vector3(0, 1, 0)).y - padding;

If anyone can assist thank you.

Hi David,

Input.GetAxis should work with most gamepads. Have you already read the description in the Unity API?

See also:

Ty ma’am I’ll look into that.

Sofar I’m able to move the paddle with the controller only left & right. But it’s strange because up & down are left & right & left & right do nothing.

I have to also get the ball to shoot by pressing A on my gamepad. I believe I can use the code Rick gave us in laser defender/tilevainia for pressing buttons to make something happen.
I still would like left & right to be left & right not up & down but Rick teaches us to get things functioning first then work on tweaking it.

I’ve always wanted to show you some of my game. This is from the beta I released Jan.

So right now the issue is the Vector2 paddleToBallVector;/LockBallToPaddle(). What happens is the new controls don’t have that parameter & if I use the old controls the mouse still is the only controller. Then the ball is also looking for that paddle in the inspector & without the paddle.cs on the paddle I can’t connect paddle to ball. So I think what I need to do is work on my paddle code to have it control the paddle with the controller & have it still be able to place the ball in the right spot.
I’m not sure how I’m gonna get this done atm.

I may not need to solve that issue. I’m going to try something slightly different.

This topic was automatically closed after 16 days. New replies are no longer allowed.

Privacy & Terms