Brick Breaker- Ball does not bouncing back from the brick

When my ball is touching a brick it does not bounce back from it but it gets through that brick and destroys it.
I’m a high school student and know almost nothing in unity, I will appreciate if the answer will be well explained so I could understand it…

here is the brick code:

using UnityEngine;
using System.Collections;

public class Bricks : MonoBehaviour {

// Use this for initialization
void Start () {

}

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

}

void OnCollisionEnter2D(Collision2D col){
	if (col.gameObject.tag == "ball") {
		Destroy (gameObject);		
	}

}

} ,I have a problem… When my ball is touching a brick it destroys it and gets through it, but it doesn’t bounce back from that brick. Can anyone help me fix it?

using UnityEngine;
using System.Collections;

public class Bricks : MonoBehaviour {

// Use this for initialization
void Start () {

}

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

}

void OnCollisionEnter2D(Collision2D col){
	if (col.gameObject.tag == "ball") {
		Destroy (gameObject);		
	}

}

}

Hi there @OfirAharoni

The problem is that your ball is destroying the brick and providing no logic to bounce back off of it. You would ideally call a method that performs an algorithm that will reflect the ball from the brick using either Vector3.Reflect() or even Rigidbody2D.AddForce. But, seeing as you are watching a beginner’s video I feel like you’ve meant to use a Physics2D Material and create a “bouncy” physics material which you then assign to the ball’s circle collider. This will ensure that your ball will bounce off of anything that contains a 2D collider, although this is not the best or most controllable way, it’s the easiest and the far more likely reason your ball is not bouncing.

Also, if you know absolutely nothing about Unity I would strongly recommend/advise you watch the tutorials contained within the learn section as they teach you everything to do with the built-in Physics, GameObjects, Animator’s and even the scripting system, along with teaching you how to make games. Consulting these before jumping in to make a game is the wisest decision otherwise you will find yourself asking these types of questions often.

I hope this helps! :slight_smile: