Block Breaker finished and polished version

Hello, i have this project unfinished for a while. And now i can release it.
Try out my game, share your opinion in comments!

2 Likes

Very nice, I especially like how the ball goes in the direction of where you hit it with the paddle. Haven’t done that with my own yet.

Did you make a paddle with three child game objects? For example attach the paddle script to the parent game object and then have if statements for left, middle and right. With a different velocity output?

Actually you take coords of paddle center and hit point coords. If hit coords < center ball goes left. If hit coords > padle center ball goes right.

    private void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Ball")
        {
            Rigidbody2D ballRB = coll.gameObject.GetComponent<Rigidbody2D>();
            Vector3 hitPoint = coll.GetContact(0).point;
            Vector3 paddleCenter = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y);

            ballRB.velocity = Vector3.zero;
            float difference = (paddleCenter.x - hitPoint.x)*initialBallSpeed;

            if (hitPoint.x < paddleCenter.x)
            {

                LeftDir(ballRB, difference);

            }
            else
            {

                RightDir(ballRB, difference);

            }
        }
    }

     void LeftDir(Rigidbody2D ballRB, float difference)
    {
        ballRB.AddForce(new Vector2(-Mathf.Abs(difference), 2f * initialBallSpeed - 0.56f * Mathf.Abs(difference)));
    }

     void RightDir(Rigidbody2D ballRB, float difference)
    {
        ballRB.AddForce(new Vector2(Mathf.Abs(difference), 2f * initialBallSpeed - 0.56f * Mathf.Abs(difference)));
    }
2 Likes

Very cool looking implementation of the block breaker theme. The bright effects on the blocks etc really make it stand out. Also that it let me continue with current level even after loosing both lives is nice.
The power up that looks like a fireball doesnt have a sfx i think I would suggest adding something for that as well. Also came across a bug in one level where the ball hit the paddles side and was sent to the side parallel to the bottom and the game didnt detect that it was no longer in the game view leaving me with just the paddle.

1 Like

I was very surprised when the ball exploded and the popcorn that came out cleared the level for me :smiley: lol. I like your design very much (even though it hurts my eyes). I was also glad I could continue playing because I died tons of times. ahaha!! Are the glowing effects on the bricks you’re using, done through shader effects?

1 Like

The glowing effect is simple material with emission turned on and albedo is a sprite that you can draw in paint.
And then you make script with material offset over time and put it on game object with that material.

public class MaterialOffset : MonoBehaviour
{
    [SerializeField] float scrollX = 0.5f;
    [SerializeField] float scrollY = -0.5f;
    new Renderer renderer;

    private void Start()
    {
        renderer = GetComponent<Renderer>();
    }

    private void Update()
    {
        float offsetX = Time.time * scrollX;
        float offsetY = Time.time * scrollY;
        renderer.material.mainTextureOffset
	 = new Vector2(offsetX, offsetY);
    }
}

I played my game and this bug newer happened.
Thanks for detecting it, ill fix this problem.

I implemented your code to my game today, I’m going for a 3D style block breaker. So I just had to tweak a bit of it from 2D to 3D, my ball runs on the x and z axis.

It works well the only thing that was causing me issues was when I was using ballRB.AddForce when the ball hit the paddle it came to a complete stop, I changed it to ballRB.velocity and it started to work.

Thank you for sharing.

1 Like

Yes the ball suppose to stop, but its stopped for 1 frame.
Its because you need to change its velocity independent on reflect.

I also recommend you to watch this tutorial for a ball

1 Like

Apologies, what I meant was it came to a complete stop and lost momentum so it wasn’t moving anymore.

Changing it to .velocity though fixed it.

Ok, this is right decision.
I think addforce didnt work because of mass. My ball mass is 0.23.

1 Like

Privacy & Terms