Without using the "on edge, bounce" command....
and using a variable
Last edited by superllama (2010-05-06 08:44:05)
Offline
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
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
Offline