Wall ball bounce

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bigs
    New Member
    • May 2007
    • 8

    Wall ball bounce

    Source:
    http://fileho.com/download/120846695042/bounce2.zip.htm l

    How would I go about making a wall for my bouncing ball?
    For example if the ball hit the center box it would bounce.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Bigs
    Source:
    http://fileho.com/download/120846695042/bounce2.zip.htm l

    How would I go about making a wall for my bouncing ball?
    For example if the ball hit the center box it would bounce.
    Well, I'm not going to download those files and I know a few others who wont as well. It's better if you tell us what characteristics you want your wall to have. The bouncing can be controlled by tracking the position of the ball on the canvas (or whatever it is you are using) and changing the direction of the ball as soon as it enters certain coordinates. You can even make the wall invisible.

    Comment

    • Bigs
      New Member
      • May 2007
      • 8

      #3
      Originally posted by r035198x
      Well, I'm not going to download those files and I know a few others who wont as well. It's better if you tell us what characteristics you want your wall to have. The bouncing can be controlled by tracking the position of the ball on the canvas (or whatever it is you are using) and changing the direction of the ball as soon as it enters certain coordinates. You can even make the wall invisible.
      It is a little hard to describe without actually seeing it. Well, basically I have two boxes:
      Code:
      	   g.drawRect(10,0,950,500);
      	   g.drawRect(350,170,200,150);
      One box inside the other, right now the ball will bounce inside the first box, but the part I am having trouble with is making the inside box also make the ball bounce when hit.

      For the first box I just took the x or y and then changed direction example:
      Code:
               if  (x > 910)                 /** bounces back left when x = 910 */   
               {dir = dir - 2;}
      But, because the other box is on the inside it will not work. I need to find out how to add walls that the ball will bounce off of. Preferably something that will not require at lot of check for the ball going into a certain point. But, anything that works would be great.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Bigs
        It is a little hard to describe without actually seeing it. Well, basically I have two boxes:
        Code:
        	 g.drawRect(10,0,950,500);
        	 g.drawRect(350,170,200,150);
        One box inside the other, right now the ball will bounce inside the first box, but the part I am having trouble with is making the inside box also make the ball bounce when hit.

        For the first box I just took the x or y and then changed direction example:
        Code:
        if (x > 910) /** bounces back left when x = 910 */ 
        {dir = dir - 2;}
        But, because the other box is on the inside it will not work. I need to find out how to add walls that the ball will bounce off of. Preferably something that will not require at lot of check for the ball going into a certain point. But, anything that works would be great.
        I still don't get the problem. What's different for the second box except for the co-ordinates? Can't you do it the same way you did with the first box?

        Comment

        • Bigs
          New Member
          • May 2007
          • 8

          #5
          Originally posted by r035198x
          I still don't get the problem. What's different for the second box except for the co-ordinates? Can't you do it the same way you did with the first box?
          The box is inside the other box. The reason I cant do it the same way is because it would be blocking the ball from moving freely in the first box because it would section off the entire area from that point. Think of it this way I have a pool of water and there is an island inside the pool.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Bigs
            The box is inside the other box. The reason I cant do it the same way is because it would be blocking the ball from moving freely in the first box because it would section off the entire area from that point. Think of it this way I have a pool of water and there is an island inside the pool.
            Ok. What's wrong with using :
            The leftmost side of the box is at 350 + 200 = 550.
            [CODE=java] if (x > 550) /** bounces back left when x = 550 */ {

            dir = dir - 2;

            }

            [/CODE]
            Last edited by r035198x; Jun 1 '07, 07:08 AM. Reason: removed the mess

            Comment

            • Bigs
              New Member
              • May 2007
              • 8

              #7
              It is because it is still counting for both inside and outside, box.
              For example it may hit the inside box point and bounce but the program is also considering the entire point from there on. Making a line across causing the ball to bounce before it touches an outside corner as well. Bouncing off nothing.


              Could you please look at the full program code, it is kind of hard to explain in words.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by Bigs
                It is because it is still counting for both inside and outside, box.
                For example it may hit the inside box point and bounce but the program is also considering the entire point from there on. Making a line across causing the ball to bounce before it touches an outside corner as well. Bouncing off nothing.

                Could you please look at the full program code, it is kind of hard to explain in words.
                So you don't want the ball to get into the inner box?
                You need to test both the x position and the y position deepending on the direction of the ball. e.g if the ball is travelling from left to right, do

                if x >= 550 and if y is between 20 and 170 then move the ball back to the left

                Comment

                Working...