This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-10-26 09:10:06

addixx001
Scratcher
Registered: 2009-10-26
Posts: 2

pong. how to...

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

 

#2 2009-10-26 23:57:45

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: pong. how to...

Does this help: http://scratch.mit.edu/projects/Magnie/701486 ?

Offline

 

#3 2009-10-27 01:10:10

WeirdF
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: pong. how to...

It's simple, just use this script on the ball:[blocks]

<forever if><touching[ paddle
<point in direction( (( <direction> <-> 180 ))[/blocks]


http://i.cr3ation.co.uk/dl/s1/gif/847032b8a331def77529b6a0384db1fe_handfingers.gif

Offline

 

#4 2009-10-27 01:53:45

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: pong. how to...

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

 

#5 2009-10-28 21:18:09

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: pong. how to...

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  wink

Last edited by Locomule (2009-10-28 23:13:31)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#6 2009-10-29 03:38:21

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: pong. how to...

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.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#7 2009-10-29 14:58:58

addixx001
Scratcher
Registered: 2009-10-26
Posts: 2

Re: pong. how to...

thanks man. im in class right now and cant open it up, but ill check it when i can and get back here asap.

Offline

 

#8 2009-10-29 16:21:46

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: pong. how to...

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.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#9 2009-10-29 16:53:05

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: pong. how to...

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.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer