This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-05-06 08:35:57

superllama
Scratcher
Registered: 2010-05-01
Posts: 2

How to make ball bounce?

Without using the "on edge, bounce" command....
and using a variable

Last edited by superllama (2010-05-06 08:44:05)

Offline

 

#2 2010-05-06 12:32:43

DaedalusYoung
Scratcher
Registered: 2010-05-05
Posts: 8

Re: How to make ball bounce?

I tried this, but it is either impossible or very hard. To do it properly, that is.
You see, the problem is that while you know the direction of your ball, let's say it's 135 degrees (pointing to the bottom right), you really need to know the impact angle.
If said ball hits a horizontal line, or paddle or bottom of screen, it should bounce back at 45 degrees. Now that all may look simple, but what if it didn't hit a horizontal line, instead it hit a vertical line? Then, the bounce degree should be -135 degrees.
If it hits a diagonal line, it will get even worse.
You can workaround some of this, have separate sprites for horizontal and vertical bounce surfaces, but to do this on more complex sprites (such as individual blocks in a Breakout game, which then would consist of 4 sprites (top, bottom, left and right sides), the ball changes direction depending on which of the four it hits, the hit sprite then broadcasts a message it is hit and all 4 sprites hide, not very efficient) it's I think more or less impossible to do properly without knowing the impact angle.
It would be much easier if the "on edge, bounce" block was changed to simply a "bounce"-only block and you could use any if-statement (hit another sprite, hit a color, hit the edge, anything like that) to trigger the bounce.

Offline

 

#3 2010-05-06 13:44:19

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: How to make ball bounce?

DaedalusYoung wrote:

I tried this, but it is either impossible or very hard. To do it properly, that is.
You see, the problem is that while you know the direction of your ball, let's say it's 135 degrees (pointing to the bottom right), you really need to know the impact angle.
If said ball hits a horizontal line, or paddle or bottom of screen, it should bounce back at 45 degrees. Now that all may look simple, but what if it didn't hit a horizontal line, instead it hit a vertical line? Then, the bounce degree should be -135 degrees.
If it hits a diagonal line, it will get even worse.
You can workaround some of this, have separate sprites for horizontal and vertical bounce surfaces, but to do this on more complex sprites (such as individual blocks in a Breakout game, which then would consist of 4 sprites (top, bottom, left and right sides), the ball changes direction depending on which of the four it hits, the hit sprite then broadcasts a message it is hit and all 4 sprites hide, not very efficient) it's I think more or less impossible to do properly without knowing the impact angle.
It would be much easier if the "on edge, bounce" block was changed to simply a "bounce"-only block and you could use any if-statement (hit another sprite, hit a color, hit the edge, anything like that) to trigger the bounce.

There is a workaround that lets you use if on edge bounce, but it isn't that accurate and has glitches:

http://scratch.mit.edu/projects/justtestingstickman/970730


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

Board footer