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

#1 2009-03-25 21:58:42

mb1350
Scratcher
Registered: 2009-03-25
Posts: 9

How do you get a ball to bounce off a paddle?

Here's one part of my project that I need help on:

The concept is fairly simple: there's a ball, a paddle, and a block that randomly spawns in the screen. You hit space and the ball starts moving. you hit the ball with the paddle and try to hit the block with the ball.

The way I have it working now is when the ball contacts the paddle it faces up, then picks a random number from -70 to 70 and rotates that many degrees, then begins moving again. This works for the game, but it is too unpredictable. I've been trying to figure out a way to make the ball deflect like with the 'if touching wall, bounce' command, but so far I have been unsuccessful.

Does anyone have a script that will do this?

EDIT: Never mind, I figured it out. All I did was subtract 180 degrees from the direction the ball is traveling in if it is touching the paddle.

Last edited by mb1350 (2009-03-25 22:31:24)

Offline

 

#2 2009-03-26 06:52:11

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: How do you get a ball to bounce off a paddle?

study this for bouncing: http://scratch.mit.edu/projects/yambanshee/371970
Its a little bit complicated (trig can be replaced by move X steps...) but it is the easiest way to do real bouncing. point in direct of the paddle + 180 on it own wont work

Offline

 

Board footer