Bouncing Ball in Scratch
I made this for the contest
Supplies
https://scratch.mit.edu
Sprite
Create a simple sprite of a ball, it can be a different shape, but for this I am using a ball.
Variables
make these three variables: ambounces (# of bounces to do) bounces (total bounces done) velocity (speed)
Coding 1
after the flag block add a go to block and set that to 0, 120. Then add the set variable to blocks. Set velocity to 1, bounces to 0 and ambounces to the amount of bounces the ball should do (Technically it is how many times the ball touches the floor, so setting it to 1 will just make it fall to the floor.) Also Add a repeat block with the amount of times it repeats set to ambounces
Coding 2
Add a repeat until block inside the repeat block and set it to 'y position < -150' Inside of that add a change y by block and set that to 'velocity * -1' Under that add a change velocity by 1 block. Outside the repeat until block add a set y position to -150 block.
Coding 3
Under the set y to -150 block, but still inside the repeat ambounces block, add a change bounces by 1 block. Underneath that is a very confusing formula. Set Velocity to Velocity * (-0.8 - ((Bounces * -0.015) - ((20 / Ambounce) * 0.06)))
The gist of the formula is kind of hard to explain but here is it in simple terms
- Sets velocity to velocity * -0.8 which makes the velocity negative (makes it go up) and smaller (doesn't go up as high)
- The second part with the Bounces block makes it so as the bounces go up it gets smaller
- The Third part with the Ambounce block makes it so the more bounces the ball should do, the bigger it is
- The formula is basically -0.8 - (#1 - #2.) The more bounces the ball does makes #1 more negative, and the lower Ambounce is, it makes #2 more positive.
Example If Velocity is 10, Bounces is 4 and Ambounce is 7. Than it equals 10 * (-0.8 - ((4 * -0.015) - ((20/7) * 0.06) * 0.06))) which equals -5.69
Background
Set a background, this could really be anything but I made mine pretty simple.
Done
That's it. You can change the Ambounce value to get a different simulation, I find that around 6-10 bounces looks the best. You can also change the numbers in the formula to make it look how you want.
https://scratch.mit.edu/projects/1277878978/