Thread: Breakout althorigm help!!!

  1. #1
    Computer guy
    Join Date
    Sep 2005
    I'm lost!!!

    Breakout algorithm help!!!

    In a breakout game, the simplest way to determine if the ball hits the block is define the coordinates of the block, and when the ball is in the specific coordinate, the ball hits the block. The ball direction will be invert by positive/ negative 'speed'.
    ex: if(hit==true)
    speed *= -1;

    But what if the ball is go straight into a corner of the block, what direction would the ball head to??? I've been dealing with this matter for like a week already and still haven't figure out. The speed of the ball also relative to the coordinate of the place where collision occur. The speed is faster, the colliding areas must be bigger.

    when i want to determine if the ball only hit the left side of the block. I would create a bounding box around the left side of the block. Let just say "block.x" and "block.y" are the top-left of the block. "Ball.x" and "Ball.y" are the center of the ball, the ball has a radius of 10. Block's length is 30, width is 15.
    if( (Ball.x+10 >= block.x-1) && (Ball.x <= block.x-11))
        if( (Ball.y+10 <= block.y+25) && (Ball.y-10 >= block.y))
                return NormalLeft;
    The code works at certain point but it always goes wrong when it's near the corner.

    So can anyone point out how can i fix this problem. By the way, i don't use the "invert speed" way to change the direction of the ball, but actually calculate the ball's angle with the blocks' normal.
    Last edited by hdragon; 02-20-2006 at 07:26 PM.
    Hello, testing testing. Everthing is running perfectly...for now

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    What you actually need to do is create normals for each side of the block. The normals for your block (in DX) are:

    Left -1.0,0.0,0.0
    Top - 0.0,1.0,0.0
    Right - 1.0,0.0,0.0
    Bottom 0.0,-1.0,0.0

    Do an AABB bounding box collision text between the ball and the brick. Find the interval of collision and if it is not empty then:

    Multiply the ball velocity vector or direction vector by the normal of the surface of the block that the ball has hit.

    If you don't want to do it this way you can use bounding boxes to encase sections of the bricks. Then test the sections and if the test passes (the ball has hit this area) then just switch the sign of the correct component of the ball vector.

    if (AABBCollide(Ball,LeftSideOfBlock))
    Last edited by VirtualAce; 02-21-2006 at 12:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Breakout Collision Detection Algorithm Help
    By xmltorrent in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 02:32 PM
  2. Reference to making breakout game
    By Raison in forum Game Programming
    Replies: 10
    Last Post: 12-31-2004, 05:18 PM
  3. Turman-Nate (BreakOut Clone) 0.01
    By cMADsc in forum Game Programming
    Replies: 5
    Last Post: 04-27-2003, 02:46 PM
  4. breakout collision
    By lambs4 in forum Game Programming
    Replies: 5
    Last Post: 03-13-2003, 03:23 PM
  5. Best breakout clone ever made.
    By funkydude9 in forum A Brief History of
    Replies: 1
    Last Post: 11-15-2002, 10:25 PM