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

#1 2009-11-05 13:53:00

DigStuTest
Scratcher
Registered: 2009-07-13
Posts: 3

Script for ball bounce in 2Pong

I am new to Scratch and cannot figure this out.

Looking at: http://scratch.mit.edu/projects/SampleProjectsTeam/62832

I've copied their blocks for the ball bounce

<when green flag clicked>
<forever><move( 4 )steps><if on edge, bounce>

And it works fine with their ball but I cannot use any other ball from the Things menu.  What am I doing wrong?!

Thanks!

Offline

 

#2 2009-11-05 14:11:15

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: Script for ball bounce in 2Pong

What you should do is put THOSE scripts on the other balls.

Offline

 

#3 2009-11-05 14:16:28

DigStuTest
Scratcher
Registered: 2009-07-13
Posts: 3

Re: Script for ball bounce in 2Pong

Yep, that's what I've done.  It bounces up and down just fine, but it doesn't drift from left to right at all after bouncing back.  I'm not worrying about the paddle at all yet, I just want to make the ball bounce correctly.

Offline

 

#4 2009-11-05 14:28:53

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

Re: Script for ball bounce in 2Pong

and then they still won't work. Or more specifically, will only work sometimes on the top and bottom, but not the sides. Check out my Pong for working bounce routines but remember, the paddles figure 'correct' angles first, then they adjust them according to how far the ball bounces from the center of the paddle. I think the mods should create a Pong sticky, or maybe a Popular Game Routines sticky... seems like Pong bounces get asked for almost every day! But that was why I made mine in the first place  smile
http://scratch.mit.edu/projects/Locomule/737050
ps. the thing that messes with a lot of people on bounce/collision routines is any "Move X steps" where X is more than 1 step. At 2 or more steps, the "ball" will eventually move through or into whatever the "wall" is before the collision routine tries to make it bounce or stop. Then if it angles just right (wrong? lol) it will not make it back out of the "wall" and all heck breaks loose. That is what causes a lot of things to get "stuck" in walls.
I haven't tried it yet but taking yet another note from Archmage, 1) make the "X" (move distance) into a variable. Then add a check that checks (using x and y) to see if an object is close to a "wall". If so, change "X" to 1 until you move far enough away again.
So the point is that if you have really fast moving objects (bullets, etc) you can expect extra problems. When you tell a sprite to do a big jump like "Move 15 steps" it is gonna basically going to jump from point A all the way to B before it does anything else in the script. You can put your collision detection/bounce routine into a separate block from your Move block (I would consider that Parallel vs. Series) but this will eventually cause weird problems that can be hard to diagnose. Peace.


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

Offline

 

#5 2009-11-05 14:30:40

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

Re: Script for ball bounce in 2Pong

Ok, I never expect to anything I do to truly be original here but anyway...
I am going to make a short series of tutorials that cover common problems and solutions to this. I know my rambling forum posts can be hard to suffer through, much less understand.


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

Offline

 

#6 2009-11-05 16:23:28

DigStuTest
Scratcher
Registered: 2009-07-13
Posts: 3

Re: Script for ball bounce in 2Pong

Thanks very much, I'm going to take a look at your scripts.

Offline

 

#7 2009-11-06 00:55:41

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

Re: Script for ball bounce in 2Pong

Cool, just holler if they are confusing, or if you come up with improvements!!  smile


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

Offline

 

Board footer