I'm looking for a simple example of how to do ball-bouncing, including the bounces at the end when it hits the ground, or change of rotation when it hits a wall. Simulations of gravityy, etc. I've seen some complex examples but I don't really understand how they work.
Offline
Have a look at this and see if it helps...
http://scratch.mit.edu/projects/Ratty1967UK/1207378
Offline
Well why need to go to that link? (No offense) But there is a faster way. Just go to the Scratch program open Scratch, click file, click open, click examples, click Pong, take a look at their scripts and *drum roll* you have it!
Offline
none taken although the Pong example doesn't mimic the effects of gravity...well, not on my planet! hehehe
Offline
If you want gravity to be applied to the ball, tell it to decelerate 9.8m/s, which is approximately the effect of gravity, you can unify each step to be a meter, making it 9.8 steps a second, then divide that by around 30 to make it slow by about 0.327 steps a frame (I might be wrong, I'm just assuming that scratch runs at 30fps).
<forever>
<change{ y velocity }by( -0.327 )
<if on edge, bounce>
^That I think would mimic the constant pull of gravity.
Use the variable Y velocity, or another variable with a different name to tell how many steps the sprite will move, and use <change y by( <{ y velocity }> for the motion of the sprite you're going to make move, it'll move on the up/down or y axis at the speed that will be effected by gravity.
For hitting the ground try
<if><touching[ ground ]>
<point in direction( (( 180 <-> <direction> ))
and for a wall, try
<if><touching[ wall ]>
<point in direction( (( 0 <-> <direction> ))
I hope this helps!
Last edited by Flait7 (2011-07-18 23:08:37)
Offline
I made a small project to do exactly what you want, at least, to my understanding. You can view it here: http://scratch.mit.edu/projects/demosthenes/556255.
If you have any questions, feel free to ask, preferably by commenting on the project, that way, I will get a notification.
Offline