Power-ups in block breaker

Hello!
I’m making my Block Breaker game. I managed to add multi-ball and lives system. I’m trying to make powerups. For now, my power-ups spawn from Bricks when they are destroyed (like the sparkles, but with some probability of occurring), and are “pushed” down to the bottom. What i’m trying to do, is to handle a collision between Paddle and PowerUp objects. Like, when the Power-up hits the Paddle, something happen (for now, i just want to destroy the PowerUp object, and then e.g. add new ball to my game). When i set my PowerUp as dynamic Rigidbody, it is destroyed when hits the Paddle, but also bounces off the ball and blocks, so it is not what i’m trying to achieve. But, when i change the Powerup RigidBody to Kinematic, nothing happens when it hits the paddle. Any solution ?

PowerUp class:

 private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Paddle")
        {
            Destroy(gameObject);
            //TODO: Add new ball
        }
    }

Block class:

    private void PowerUp()
    {
        if (powerUpProbability >= UnityEngine.Random.Range(0, 100))
        {
            GameObject newPowerup = Instantiate(powerups[0], transform.position, transform.rotation);
            newPowerup.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, -4f);
        }
    }

Hi,

Two things I would do initially;

  • check that the Is Trigger property isn’t enabled on the power-up
  • use a Debug.Log statement in your OnCollisionEnter2D method, right at the beginning, before any logic to see if it is called.
1 Like

Hi,
Thanks for your reply.

I checked and the Is Trigger property on the power up is disabled. I tried with enabled and disabled previously anyway and nothing changed.
I used the Debug.Log statement and there is no notification in the Console. I think it’s because of the “Kinematic” Body Type. When i changed it to dynamic, notification in Console appeared. What i’m trying to achieve is that the Power Up goes down on my camera like a ghost, through the bricks and ball, but call the collision when hit the paddle (and only paddle).

1 Like

You’ll need to use layering. A quick rundown…
screen1


2 Likes

Thank you very much. That’s exactly what I was looking for. I’m new to Unity and knew nothing about those layers etc. Now the power ups works perfect.

1 Like

No problem at all. I nailed down layering a whopping 2 days ago myself. Been going pretty hard at since I started with Unity a couple weeks ago.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms