how do you get the ball sprite to bounce off of the paddle at an angle that corresponds to the distance from the center of the paddle that the ball lands at? i am creating a pong game for my computer science class and want it to be just a little better.
Offline
Does this help: http://scratch.mit.edu/projects/Magnie/701486 ?
Offline
That makes the ball go in the opposite direction it came from, why does everyone give out that script? It doesn't really work...
Offline
http://scratch.mit.edu/projects/Locomule/709464
That covers the correct bouncing on horizontal boundaries. To have the angle affected by the distance from the center of the paddle is easy. Adjust the figured bounce angle by subtracting the ball's y value from the paddle's y value (or vice versa) and add the difference to the already figured bounce angle. To tweak the amount of angle adjusted, multiply the y-y by tiny amounts until it functions correctly.
ie....
(y-y)*1.1 or (y-y)*.9 etc
Peace
ps.. I've wanted to do a Pong for a while myself so I'm gonna start on mine tonight. Will have it finished asap and I'm gonna do it using all original scripting, if I can
Last edited by Locomule (2009-10-28 23:13:31)
Offline
Ok, done. Here is my pong...
http://scratch.mit.edu/projects/Locomule/737050
I ran into multiple issues and it still has one that I know of but all things considered I'd say it works pretty well. You play against the computer, controlling the right side with your mouse. First one to 10 wins.
Offline
No prob! I tried to keep it simple (for future peeps) but now I'm itching to redo it without using "If Touching"s or "Move"s. I'm gonna tweak this some more later too. Peace.
Offline
And in response to Magnie's reply...
Due to the way Scratch's angles were setup, the commonly expected usage of "direction * -1" ONLY works when something bounce off the right or left side. My solution for the bouncing things off the side walls/barriers is (drumroll please)
"180 - direction"
Yayyy, it works! Of course, you also have to use 2 variables to keep up with whether the object is moving up or down and left or right but I'm will start working soon (tonight?) on a way around that (mentioned above.) Toodles.
Offline