Block Breaker - Slow Ball Fix!

Hopefully someone can find this useful. This is my fix for the Block Breaker game where the ball will slow down until the game is unplayable. With this fix I was able to auto-play my game (5 levels) all the way through 2/3 times on my first test. Before the fix, I could try 5 times and still not be able to auto-play through once. On Ball.cs:

private void OnCollisionEnter2D (Collision2D collision)
{
//Artificial physics to try and stop infinite looping. TODO find a better fix.
Vector2 velocityTweak = new Vector2(Random.Range(0f, randomFactor),
Random.Range(0f, randomFactor));

    if (hasStarted)
    {
        AudioClip clip = ballSounds[UnityEngine.Random.Range(0, ballSounds.Length)];
        myAudioSource.PlayOneShot(clip);

        //Assigns the balls speed to 15 and keeps it there
        myRB2D.velocity = myRB2D.velocity.normalized * 15f;
        //Add the random tweak to the set velocity of 15 (I do 0.4, seems to work well).
        //This gives us a value between ~14.6 and ~15.4 every time
        myRB2D.velocity += velocityTweak;
        print(myRB2D.velocity.magnitude);
    }
    
}
3 Likes

Thanks! For your help!

This fixed my slowing ball issue. Thanks!

Thank you Camran, that fixed my sloooow motion :slight_smile:

Excellent results with this so far. I changed 15f to 18f to speed up the ball worked a treat :slightly_smiling_face:

If you change the speed to like 19f then put random factor to 1 it makes the ball move much better for my first level. Excellent scope for experimenting here.

Privacy & Terms