Search Unity

BrickBreaker / Breakout Clone - Help with boucning left to right indefinitely.

Discussion in 'Scripting' started by daggasoft, Jul 25, 2013.

  1. daggasoft

    daggasoft

    Joined:
    Jun 29, 2013
    Posts:
    22
    I have the same issue as this guy, http://answers.unity3d.com/questions/31643/breakout-style-ball-getting-stuck-horizontally.html

    However his solution of rotating the walls seems a little off to me. I've seen a number of posts on this exact question but no defined answers. Would like some input.

    The issue of course is the ball can get stuck bouncing perfectly on the X axis with no angle, or perfectly on the Y. So bouncing left to right in between two objects such as the walls, forever. Or bouncing up and down between two objects such as the ceiling and a non-distructable object.

    In my opinion it is actually desired to have this behavior for a certain number of bounces. Especially with my game's particular spin on the classic game play. I may want it going left to right perfectly in order to break apart certain bricks with high hit points. But I think I should add a way to detect if it's stuck in a loop and then add some artificial nudge.

    Such as, IF the last say 1000 frames (or # of seconds) havent changed on the X then add force on the Y. IF frames havent changed on the Y then add force on the X.

    I have no idea how I'd accomplish this. Does what I'm proposing make sense and does anyone have a suggestion?

    Thanks.
     
  2. daggasoft

    daggasoft

    Joined:
    Jun 29, 2013
    Posts:
    22
    Further I'd like to add that it's not always an issue with no change on the x or y, sometimes it will bounce off a block on a very slight angle and it just leads to boring game play.

    I'm thinking that On Collision, determine what angle it would bounce back at, and if it's less than some acceptable range, cap it to the bare minimum of what the acceptable range is.

    As in if the bounce back angle would have been 5 degrees, but 5 degrees is boring, change the bounce back angle to say 15 degrees. Does this make sense?

    I'm very new at coding in unity and have never been a very good programmer, but I've managed to muddle my way through this, have a large number of features, and nearly bug free (at face value) with the exception of this outstanding issue. Any hand holding would be appreciated as I'll learn from it.
     
  3. Raimi

    Raimi

    Joined:
    Aug 2, 2014
    Posts:
    6
    Hi.

    you could check the y velocity and add rotation.

    Code (CSharp):
    1. if(ball.velocity.y == 0)
    2. {
    3. //do something
    4. }
    I know this threads quite old, but might help someone
     
    Valky143 likes this.