Discuss Scratch

awesomedomination8
Scratcher
100+ posts

Bouncing off sprites

I am trying to make a sort of Pong game, but I am trying to make it so that the ball bounces off the paddles, and I've already tried this.
whenclickediftouchingpaddle 1?ortouchingpaddle 2?thenturnccw180degrees
(I'm not good at scratch blocks on forum…)
Please help!
BKFighter
Scratcher
1000+ posts

Bouncing off sprites

From an earlier post:
Oct. 11, 2013 19:07:24
Locomule

Scratcher
100+ posts
I Need Help Making the Wall Bounce Look Realistic
Just as a fyi, here are the formulas for changing direction instead of flipping X and Ys…

Side wall reflections are just direction * -1

Top and bottom wall reflections are 180 - direction

You still have to deal with corners where you hit two walls at once. My solution is to use either color sensing with different colored walls or 4 sprites. Either way, I use a 2 entry list to keep up with which walls, if any, the ball is touching. Since I'm using a list, it also allows me to verify which wall was hit last when touching two walls at once. Then I just figure the angle for the second wall, move the ball until it is no longer touching the second wall (It will not be touching the first either by then) and then clear my list of which walls the ball is touching.

Now the ball has bounced off both corners correctly and is back in play. I wrote this and tested it, it works. I will upload the project tonight or tomorrow, whenever I get a chance to get my laptop online.
___________________________________________________________________________
Need help? Try the Scratch Wiki!

Report | Quote
#12Oct. 12, 2013 13:06:54
Locomule

Scratcher
100+ posts
I Need Help Making the Wall Bounce Look Realistic
Here it is
___________________________________________________________________________
Need help? Try the Scratch Wiki!

Report | Quote


Link: https://scratch.mit.edu/discuss/topic/17687/?page=1#post-162096
awesomedomination8
Scratcher
100+ posts

Bouncing off sprites

BKFighter wrote:

From an earlier post:
Oct. 11, 2013 19:07:24
Locomule

Scratcher
100+ posts
I Need Help Making the Wall Bounce Look Realistic
Just as a fyi, here are the formulas for changing direction instead of flipping X and Ys…

Side wall reflections are just direction * -1

Top and bottom wall reflections are 180 - direction

You still have to deal with corners where you hit two walls at once. My solution is to use either color sensing with different colored walls or 4 sprites. Either way, I use a 2 entry list to keep up with which walls, if any, the ball is touching. Since I'm using a list, it also allows me to verify which wall was hit last when touching two walls at once. Then I just figure the angle for the second wall, move the ball until it is no longer touching the second wall (It will not be touching the first either by then) and then clear my list of which walls the ball is touching.

Now the ball has bounced off both corners correctly and is back in play. I wrote this and tested it, it works. I will upload the project tonight or tomorrow, whenever I get a chance to get my laptop online.
___________________________________________________________________________
Need help? Try the Scratch Wiki!

Report | Quote
#12Oct. 12, 2013 13:06:54
Locomule

Scratcher
100+ posts
I Need Help Making the Wall Bounce Look Realistic
Here it is
___________________________________________________________________________
Need help? Try the Scratch Wiki!

Report | Quote


Link: https://scratch.mit.edu/discuss/topic/17687/?page=1#post-162096
ummm… What am I supposed to do? I didn't say I needed help making wall bounces look realistic…

Last edited by awesomedomination8 (May 17, 2016 19:00:01)

JMB17
Scratcher
6 posts

Bouncing off sprites

Try getting the ball to “run away from the paddle” but just fall down again.

First, create the paddle, then the ball. Select the ball, and go to its script. Create this script:

whenclickedforeverchangeyby-1endscratchblockswhenclickedforeveriftouchingpaddle?thensetrotationstyledon't rotatepointtowardspaddleturn180degreesrepeatuntildistancetopaddle>240changeyby10/scratchblocksHopethathelped!
JMB17
Scratcher
6 posts

Bouncing off sprites

Ignore the stuff inbetween the two scripts that start with green flag, it was a mistake. Can't seem to get a handle of these darn script blocks.
awesomedomination8
Scratcher
100+ posts

Bouncing off sprites

JMB17 wrote:

Ignore the stuff inbetween the two scripts that start with green flag, it was a mistake. Can't seem to get a handle of these darn script blocks.
Yeah, neither can I… Well, thanks! I'll see if it works.
awesomedomination8
Scratcher
100+ posts

Bouncing off sprites

I've figured out the problem. Thanks everyone for helping!
lmkennedy
New Scratcher
1 post

Bouncing off sprites

SO i find this being difficult
stickfiregames
Scratcher
1000+ posts

Bouncing off sprites

lmkennedy wrote:

SO i find this being difficult
Please don't necropost (posting on old resolved topics) in this forum. It is better to make a new topic explaining what you need help with.

The way to bounce off a vertical paddle is
pointindirection0-direction
and to bounce off a horizontal paddle it's
pointindirection180-direction

This project has a custom block that can bounce off a line at any angle.

Powered by DjangoBB