Discuss Scratch

MineBlock137
Scratcher
31 posts

Pong ball physics

I am creating a game of Pong (I know, how original lol) and from what I have seen a lot of popular pong games use incorrect ball physics. From what I understand, when the ball hits a paddle, it should ignore it's previous direction and it should find it's new direction based on it's position relative to the paddle. If it is near the edge, it should in a more acute angle and it should point in a straighter direction if it is near the middle. That being said, is there any easy way to do this? Any shortcut? Because from all of my experimenting, I have yet to find a way that can fit into a single “point in direction (_)” block. Thank you!
Jareddddddd
Scratcher
1000+ posts

Pong ball physics

point in direction ((((Collider direction) + (90)) - (direction)) v)

example, a paddle that is perfectly 90 degrees flat
(look like this ————- )
MineBlock137
Scratcher
31 posts

Pong ball physics

Jareddddddd wrote:

point in direction ((((Collider direction) + (90)) - (direction)) v)

example, a paddle that is perfectly 90 degrees flat
(look like this ————- )
I appreciate it, but what is the collider direction? Additionally, if my paddle is standing up (like a capital letter “I”), would it be +180 instead? Thanks!
Conduit7
Scratcher
100+ posts

Pong ball physics

i just have a point in pick random x to y lol and it comes off as believable ¯\_(ツ)_/¯
Jareddddddd
Scratcher
1000+ posts

Pong ball physics

MineBlock137 wrote:

Jareddddddd wrote:

point in direction ((((Collider direction) + (90)) - (direction)) v)

example, a paddle that is perfectly 90 degrees flat
(look like this ————- )
I appreciate it, but what is the collider direction? Additionally, if my paddle is standing up (like a capital letter “I”), would it be +180 instead? Thanks!
nope, it works for all directions, but please note this is only one way collision so try to keep the direction a positive number (-45 would translate to 135 deg.)

example:https://scratch.mit.edu/projects/671804644/

Last edited by Jareddddddd (April 19, 2022 00:43:27)

Spentine
Scratcher
1000+ posts

Pong ball physics

I remember I experimented once with griffpatch's ball tutorial. It's supposed to be a simple ball physics engine (that would work for your game), and in order to use it for pong, you can disable the gravity and increase the bounce so that it bounces with the same velocity as before it bounced.
ggenije2
Scratcher
100+ posts

Pong ball physics

At ball sprite:
when green flag clicked
forever
if <touching [paddle1 v] ?> then
point towards [paddle1 v]
turn cw (180) degrees
move (4) steps//or try another number if it don't work
end
if <touching [paddle2 v] ?> then
point towards [paddle2 v]
turn cw (180) degrees
move (4) steps//or try another number if it don't work
end
end

I think this is self-explanatory.
The_Imaginarium
Scratcher
1000+ posts

Pong ball physics

Theoretically if a ball hits a vertical or horizontal surface, the ball will negate it's x or y velocity respectively.

Powered by DjangoBB