It does work better...maybe I'll try your formula for bouncing instead of mine...and maybe I'll have it find all the slopes previous to the actual simulation. Oh well, this is great!
Thanks! If you add that wonderful detection system for the point of contact, it'll work a lot better than this. Are you checking distance between the ball and every single "line" making up that function?
It's really nice to use Scratch for math projects, especially because of the integrated coordinate system. It's not great for algebra because of the limits of Scratch functions, but geometry works well!
The projection of the velocity vector onto the slope vector gives us a new vector that resembles the effect of the slope's absorbing all impact. If we want the ball to bounce, we use the vector rejection. It's perpendicular to the projection and the sum of the two yields the original vector (vector addition is <a,b> + <c,d> = <a+c,b+d>). The vector rejection is multiplied by -1 to create bounce, and added to the projection. http://en.wikipedia.org/wiki/Vector_projection
It uses vector math. I'll try to explain as well as I can in 500 characters. Velocity is a vector; it has two components, x and y (for vectors, you write <x,y>). The surface's slope is also a vector. We can perform an operation called vector projection that finds out how long one is along another one (projecting <a,b> onto <b,c>). The slope vector can be calculated using the points generated by the terrain generator. (continued in above comment)
Uhhhh. Why can you float? BTW, couldn't you make it adjust to slope depending on two sprites that went to the visible sprite and moved to the top? Then you could get the slope of the segment you were on by finding the difference of the y-coordinates, and using some formula for direction, have it turn to match the slope.
This project is a physics simulation, not a platforming game. It's a demonstration of accurate interactions between a round object and a sloped surface, so it is intended that the player can continuously hold the up arrow key (much like (link to project) Using "two additional sprites" approach would be slow, since "repeat" blocks in Scratch have built in wait times.
The terrain generator is a necessary part of the physics. The terrain is stored in a list (YPositions) as a sequence of y-values over the x-coordinates -240 through 240. If you want to modify the terrain, delete the "Repeat 480" section that is labeled "Land Generation" and replace it with something else. As long as the list is full, the rest will work. Maybe I'll add a "draw it yourself" feature.
Probably not. It takes way too long to regenerate the terrain. Maybe in turbo, and with a bit of fancy list programming (where it doesn't recalculate all the values each time).
This is a demonstration of (mostly) accurate roller-coaster-like slope physics.
If you love it, there's a button for that ;)
The current version (3.14.12) features sliding, bouncing, ramp-jumping, custom terrain generation, custom ball size and bounciness (restitution), and arrow key control.
Size represents the diameter of the ball. Restitution represents the amount of energy that the ball retains with each bounce.
Turbo mode suggested until it tells you to turn it off.
Stop the program, hold space, and click/hold the flag if you want to enter your own parameters for the slope.
Try these: a = 1.5 b = 1.5 c = 1.5 d = 1.5 X-Skew = 0.5 Y-Skew = 100
Or you can let yourself be surprised!
Press the spacebar during the simulation to view the current parameters.
=====
Check out applejack's cool remix with a throwable ball! (link to project)
This project was inspired in part by eRKSToCK (link to project) and VirtualClown (link to project) although I improved on the accuracy of the physics. In this model, the ball will fly when it goes over a "ramp."
=====
How it Works:
Terrain generation graphs a section of the function f(x) = sin(ax * cos(bx)) * cos(cx * sin(dx)), which is scaled and given randomly generated or user-provided parameters.
The physics scripts use the principle of vector projection (look it up on Wikipedia). This allows accurate slope rolling and pendulum-like oscillation. Vector projection is also used in by "Ball Physics" and "Elastic Collision" projects: (link to project)
=====
Known Bugs:
The ball intersects the slope on steep inclines.
The ball sticks to shallow ramps when it should fly off.
Variables in Flash are stacked on top of one another.
Random parameters in Java do not generate decimal places.
=====
Changelog:
1.17.12: Added bouncing and improved jumping (no longer based on color detection).
1.18.12: Improved bouncing to prevent "jumps." Added an upper boundary for the ball.
1.21.12: Improved jittery-ness, added a new land generation system, added hide/show terrain parameters.
1.27.12: Experimented with fixing the slope intersecting problem. The program uses a brute-force script (suggestion by applejack) that finds the point tangent to the slope at each x-value. Also replaced edge bouncing based on popular demand.
1.28.12- Removed the slope-intersecting "fix." It was too buggy. Switched to surfboard costume.
1.30.12- Reverted to ball costume. Added user-customizable properties "size" and "restitution".
Comments
You need to be logged in to post comments
Add a Comment
Neat! You really are an advanced scratcher! Thank you soooo much for your help with my project.
I'm glad to hear that! Leave me a message when you've finished, I'd like to see the complete project when it's ready.
(view all replies)No problem. I hope it works the way you want it to.
(view all replies)It does work better...maybe I'll try your formula for bouncing instead of mine...and maybe I'll have it find all the slopes previous to the actual simulation. Oh well, this is great!
Thanks! If you add that wonderful detection system for the point of contact, it'll work a lot better than this. Are you checking distance between the ball and every single "line" making up that function?
(view all replies)Amazing!
I downloaded it to see how you did all this in one script and when I opened it my mind started hurting. You are very smart : ) love it!
Haha, thanks!
You're good at math, aren't you? :P
It's really nice to use Scratch for math projects, especially because of the integrated coordinate system. It's not great for algebra because of the limits of Scratch functions, but geometry works well!
(view all replies)I suppose it is my favorite subject... haha :)
(view all replies)░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
How does this thing calculate the angle and bounce?
The projection of the velocity vector onto the slope vector gives us a new vector that resembles the effect of the slope's absorbing all impact. If we want the ball to bounce, we use the vector rejection. It's perpendicular to the projection and the sum of the two yields the original vector (vector addition is <a,b> + <c,d> = <a+c,b+d>). The vector rejection is multiplied by -1 to create bounce, and added to the projection. http://en.wikipedia.org/wiki/Vector_projection
(view all replies)It uses vector math. I'll try to explain as well as I can in 500 characters. Velocity is a vector; it has two components, x and y (for vectors, you write <x,y>). The surface's slope is also a vector. We can perform an operation called vector projection that finds out how long one is along another one (projecting <a,b> onto <b,c>). The slope vector can be calculated using the points generated by the terrain generator. (continued in above comment)
off depending on the angle it is?
i belive i can... OW!!!
Wow I love this!!!!!
Thanks! :)
Its sooo.....bouncy
Uhhhh. Why can you float? BTW, couldn't you make it adjust to slope depending on two sprites that went to the visible sprite and moved to the top? Then you could get the slope of the segment you were on by finding the difference of the y-coordinates, and using some formula for direction, have it turn to match the slope.
I could, but it wouldn't look good. The ball would appear to "jump" whenever it touched a slope. Thanks, though!
This project is a physics simulation, not a platforming game. It's a demonstration of accurate interactions between a round object and a sloped surface, so it is intended that the player can continuously hold the up arrow key (much like (link to project) Using "two additional sprites" approach would be slow, since "repeat" blocks in Scratch have built in wait times.
(view all replies)░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
How do you do that?
(view all replies)I guess you got it eventually.
░░░░░░░░█░░█░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░▀▄▄▀░░░░░░░░░░░░░░░░░░░░
░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░
▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
AWESOME
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
How do you do that? happy99 won't tell me.
Wow, everybody is doing that now because of me.
(view all replies)How did you type that?
look at my game Monster Car (link to project) I acted at the your' program Thank's!!!
nice.. but wot is turbo mode???
In the Flash player, hold shift + click the green flag.
(view all replies)Excellent project!
Thank you!
So cool!!!
Please can you check out my project (link to project)
I love it
Whoa cool
good job
This was curated! I saw it on the front page!!! (I was wondering why it had so many views) Congradgulations!
Thanks! It's my first curated project.
(view all replies)Really cool, nice physics. And guys, seriously, quit doing the COOL thing.
Lol. Thanks!
really smooth, good job. just one thing: if you press the up arrow it will keep jumping forever
glad this got curated :D
Thanks! Glad you liked it.
ok i made a remix: (link to project)
AWESOME! Can I use these physics?
I implemented a "drawable" feature. Tell me what you think!
The terrain generator is a necessary part of the physics. The terrain is stored in a list (YPositions) as a sequence of y-values over the x-coordinates -240 through 240. If you want to modify the terrain, delete the "Repeat 480" section that is labeled "Land Generation" and replace it with something else. As long as the list is full, the rest will work. Maybe I'll add a "draw it yourself" feature.
(view all replies)Sure, go ahead! Leave me a link when you're done, I'll post it in the project notes.
(view all replies)░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
How long did it take you to make this.
(view all replies)700th view!
Yay I did it!......Lol not really
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
jk i know
how do u move
think this could scroll?
Probably not. It takes way too long to regenerate the terrain. Maybe in turbo, and with a bit of fancy list programming (where it doesn't recalculate all the values each time).
epic man!
nice! I love the realistic motion and how it generates random 'levels'. one thing you could change is the ability to 'keep jumping'. great project!
Okay, thanks. The "jumping" isn't really jumping, it's reverse gravity. More like flying.
good :D
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
◔_◔
(view all replies)that game is cool
░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
ಠ_ಠ
nice!
good gravity physics on scratch, i find this type of thing really hard.
wow!
You sir, deserve a medal. You have now won Scratch.
yay works! :) :D cool!
won't open :(
1e-14 = 0.0000000000001
Yeah. I don't know why that's the upper limit. I had set it to 0 within Scratch.
(view all replies)░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░▓░░░░░░▓░░▓░░░░░░▓░░▓▓░░░░░░░░░░░░░░░ ░░░░░░░░▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓▓░░▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░█░░█░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░▀▄▄▀░░░░░░░░░░░░░░░░░░░░
(view all replies)um. wow. joletole, how did you do that?
(view all replies)Awesome game! ♥-it!
Not really a game... Still!
Reminds me of truck driving games. :3 Feels real.
amazing!!! =D can I use the scripts as a reference? I might want to make a game sometime
Sure, go ahead.
nice
you should add gravity! Still, great simulation!
maybe he wanted to make the jumping like that, that way you can't get stuck on a really steep slope.
press up :)
It does have gravity...?
(view all replies)soooo real! I love it!!!!!!
Beautiful. Love the userpic by the way.
Haha, thanks.