Discuss Scratch

psyduck926
Scratcher
10 posts

Need help with making a ball move based on where the paddle hits it in a pong game.

I'm trying to remake pong (and probably expand on it's concept after I remake the original as a base) and for the life of me I can not figure this important aspect out. I looked at multiple Pong tutorials and they all completely ignored this aspect, not even mentioning it let alone showing how to implement it. Is this just not possible in Scratch's coding system? I sure wouldn't know, I'm waaay to bad at this stuff to know. Please help D:
Catscratcher07
Scratcher
1000+ posts

Need help with making a ball move based on where the paddle hits it in a pong game.

1) Unless it involves connecting to external websockets, it is almost certainly possible in Scratch.
2) What is it? I forgot to read the title, whoops!

Last edited by Catscratcher07 (March 17, 2026 19:47:33)

Catscratcher07
Scratcher
1000+ posts

Need help with making a ball move based on where the paddle hits it in a pong game.

When you change the ball's direction when it touches the paddle, use a formula akin to
((180) + ((x position) - ([x position v] of [paddle v])))
psyduck926
Scratcher
10 posts

Need help with making a ball move based on where the paddle hits it in a pong game.

@Catscratcher07 That doesn't work as the x of the paddles never changes, only the y. I changed it from x position to y position and it seemingly did affect the gameplay but it also introduced new problems with the balls sometimes doing a little loop before going the other way and going through the paddle. I'll share the project to help demonstrate what's going on. https://scratch.mit.edu/projects/1291846793/

Last edited by psyduck926 (March 17, 2026 20:09:15)

g6g6g66g6g
Scratcher
100+ posts

Need help with making a ball move based on where the paddle hits it in a pong game.

Before you do anything, move the ball backwards so it's no longer intersecting with the paddle with
move (-10) steps
The regular way to bounce off a paddle is to use
((0) - (direction))
And if you want to bounce it purely based on where it hits the paddle, you can point towards the paddle then turn 180 degrees.

If you want a mix between the two angles, you can combine a weighted amount of the two:

set [mirror dir v] to ((0) - (direction))
point towards [paddle v]
turn cw (180) degrees
point in direction (((0.3) * (mirror dir)) + ((0.7) * (direction)))

This makes it so the “regular” way to bounce still affects the final angle, but only a little bit. Make sure the two weightings add to 1.

DEMO
deck26
Scratcher
1000+ posts

Need help with making a ball move based on where the paddle hits it in a pong game.

If the y position changes you presumably have a vertical paddle rather than a horizontal one - games exist with either so it's just a case of adjusting the advice to suit.

One useful trick to avoid the looping you describe is only to bounce if the ball is moving in the right general direction. So for a horizontal paddle at the bottom of the screen you only bounce when touching the paddle AND if the the ball's direction is less than -90 or greater than 90 (ie abs(direction) > 90). For a vertical paddle at the right you only bounce off the paddle if the ball's direction is a positive value - once you've calculated the bounce and reset the direction it doesn't matter if you're still touching the paddle since the direction will now be negative.

What I would do is use a normal bounce off a vertical paddle for (ie 0 - direction) for most of the paddle. Say the paddle is 100 pixels long. If the ball is within 40 pixels of the paddle's centre just bounce normally and only apply a correction if it is near the end. Then just tweak the bounce slightly according to the distance from the paddle's centre.
psyduck926
Scratcher
10 posts

Need help with making a ball move based on where the paddle hits it in a pong game.

g6g6g66g6g wrote:

Before you do anything, move the ball backwards so it's no longer intersecting with the paddle with
move (-10) steps
The regular way to bounce off a paddle is to use
((0) - (direction))
And if you want to bounce it purely based on where it hits the paddle, you can point towards the paddle then turn 180 degrees.

If you want a mix between the two angles, you can combine a weighted amount of the two:

set [mirror dir v] to ((0) - (direction))
point towards [paddle v]
turn cw (180) degrees
point in direction (((0.3) * (mirror dir)) + ((0.7) * (direction)))

This makes it so the “regular” way to bounce still affects the final angle, but only a little bit. Make sure the two weightings add to 1.

DEMO

I think I understand your explanation pretty well, and the project you shared works perfectly! Ty very much for the help!

Powered by DjangoBB