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);
}
}