Discuss Scratch

DanielBronfen
New Scratcher
3 posts

Bounce angle

I'm making the arcade game pong and I don't know how to calculate the angle of the bounce. Could someone help? Thanks!

Last edited by DanielBronfen (Feb. 2, 2019 17:51:20)

drchubbington
Scratcher
100+ posts

Bounce angle

Make a variable called XVel and one called YVel. Always change the x position by XVel and the y by YVel. Then, in a “run without screen refresh” myblock, change the x by XVel. If it's hitting something to bounce on, set Xvel to XVel * -1. Put it back to it's original x position and do the same for YVel and the y position.
gor-dee
Scratcher
1000+ posts

Bounce angle

Scratch uses 0 degrees = “north”, 90 = east, -90 = west & 180 (or-180) = south. So say you ball is travelling at 60 degrees toward the right hand paddle you would want it to bounce and change to -60 degrees for a symmetrical bounce which is easy
pointindirection-1*direction

you will probably want to adjust this a bit so that it isn't always symmetrical, maybe add
pickrandom-10to10

Last edited by gor-dee (Feb. 2, 2019 18:05:39)

DanielBronfen
New Scratcher
3 posts

Bounce angle

gor-dee I tried that, it doesn't work, I don't know why. As for drchubbington, could you post in blocks what you mean? I don't understand. thx
DanielBronfen
New Scratcher
3 posts

Bounce angle

Never mind I figured it out. thx anyway
if direction>0
point in direction 180-direction
else
point in direction -180-direction
Oobleck6869
Scratcher
1 post

Bounce angle

deck26 wrote:

https://scratch.mit.edu/projects/99412537/
is there a way to detect whether the ball is bouncing off of a 90- or a 0-degree angle?

Powered by DjangoBB