Discuss Scratch

sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

How should I make a ball bounce off a ball, I know how to make it bounce off flat surfaces. I'm trying to make pool.

Heres the project link. https://scratch.mit.edu/projects/942224223

Last edited by sullydux (Dec. 24, 2023 12:05:05)

RethinkingVoxels
Scratcher
1000+ posts

How should I make a ball bounce off a ball

do you want to bounce off like the
ifonedge,bounce
block?
nowayoryesway
Scratcher
19 posts

How should I make a ball bounce off a ball

maby he meant this (a LOT of blocks here)
whenclickedforevermove10stepsiftouchingwhatever sprite here?thensetdirtopickrandom1to4ifdir=1thenpointindirection45ifdir=2thenpointindirection-45ifdir=3thenpointindirection135ifdir=4thenpointindirection-135

deck26
Scratcher
1000+ posts

How should I make a ball bounce off a ball

Imagine a line joining the centres of the two balls. Now imagine a line perpindicular to that and treat that line as a flat surface you're bouncing off - that's a reasonable starting point. But it's not that simple really - if you hit a ball some or all of the momentum may be transferred to the target ball - so all you have is the angle the ball will move if it bounces off another ball but calculating the speed involves a lot more work. Presumably some sort of conservation of momentum calculations are required.

Of course this also ignores things like putting spin on the cue ball to affect how it moves.

sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

RethinkingVoxels wrote:

do you want to bounce off like the
ifonedge,bounce
block?
yea

Last edited by sullydux (Dec. 24, 2023 12:04:13)

sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

deck26 wrote:

Imagine a line joining the centres of the two balls. Now imagine a line perpindicular to that and treat that line as a flat surface you're bouncing off - that's a reasonable starting point. But it's not that simple really - if you hit a ball some or all of the momentum may be transferred to the target ball - so all you have is the angle the ball will move if it bounces off another ball but calculating the speed involves a lot more work. Presumably some sort of conservation of momentum calculations are required.

Of course this also ignores things like putting spin on the cue ball to affect how it moves.

Your project “Bounce Angle On Flat Surface” help a lot because I could not figure out how to bounce a ball on a flat surface.
Would that figure out what the surface angle is on the ball where the other ball hits it
deck26
Scratcher
1000+ posts

How should I make a ball bounce off a ball

The line I described will be a tangent to both balls - it forms a right angle with the radius of both circles. So it tells you where the contact point is and is, I think, essentially the same as a flat surface for the bounce calculation.

This project https://scratch.mit.edu/projects/174551399/ demonstrates this.
RethinkingVoxels
Scratcher
1000+ posts

How should I make a ball bounce off a ball

sullydux wrote:

RethinkingVoxels wrote:

do you want to bounce off like the
ifonedge,bounce
block?
yea
simple (kinda)
whenclickedpointindirection45optionalforevermove10stepsifonedge,bounceiftouchingBall2?thenbouncerun without screen refreshwait0.1secsdefinebouncesetlast xtoxpositionthe variable last x needs to be for this sprite onlychangexby9999ifonedge,bouncesetxtolastx
put this script in both sprites

Last edited by RethinkingVoxels (Dec. 24, 2023 13:39:21)

deck26
Scratcher
1000+ posts

How should I make a ball bounce off a ball

RethinkingVoxels wrote:

sullydux wrote:

RethinkingVoxels wrote:

do you want to bounce off like the
ifonedge,bounce
block?
yea
simple (kinda)
whenclickedpointindirection45optionalforevermove10stepsifonedge,bounceiftouchingBall2?thenbouncerun without screen refreshwait0.1secsdefinebouncesetlast xtoxpositionthe variable last x needs to be for this sprite onlychangexby9999ifonedge,bouncesetxtolastx
put this script in both sprites
Have you actually tried that? Doesn't have anything to do with the question. It seems to assume that the natural bounce depends on which edge of the screen the ball would hit if it kept going in its current direction. Do you really think the bounce angle is the same no matter where it hits another ball?
RethinkingVoxels
Scratcher
1000+ posts

How should I make a ball bounce off a ball

deck26 wrote:

RethinkingVoxels wrote:

sullydux wrote:

RethinkingVoxels wrote:

do you want to bounce off like the
ifonedge,bounce
block?
yea
simple (kinda)
whenclickedpointindirection45optionalforevermove10stepsifonedge,bounceiftouchingBall2?thenbouncerun without screen refreshwait0.1secsdefinebouncesetlast xtoxpositionthe variable last x needs to be for this sprite onlychangexby9999ifonedge,bouncesetxtolastx
put this script in both sprites
Have you actually tried that? Doesn't have anything to do with the question. It seems to assume that the natural bounce depends on which edge of the screen the ball would hit if it kept going in its current direction. Do you really think the bounce angle is the same no matter where it hits another ball?
yea, i've tried it. it answered what the question was, “How to make a ball bounce off eachother”, they said they wanted it to be like the “if on edge, bounce” block, so i made the solution.
sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

deck26 wrote:

The line I described will be a tangent to both balls - it forms a right angle with the radius of both circles. So it tells you where the contact point is and is, I think, essentially the same as a flat surface for the bounce calculation.

This project https://scratch.mit.edu/projects/174551399/ demonstrates this.
thanks
sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

RethinkingVoxels wrote:

deck26 wrote:

RethinkingVoxels wrote:

sullydux wrote:

RethinkingVoxels wrote:

do you want to bounce off like the
ifonedge,bounce
block?
yea
simple (kinda)
whenclickedpointindirection45optionalforevermove10stepsifonedge,bounceiftouchingBall2?thenbouncerun without screen refreshwait0.1secsdefinebouncesetlast xtoxpositionthe variable last x needs to be for this sprite onlychangexby9999ifonedge,bouncesetxtolastx
put this script in both sprites
Have you actually tried that? Doesn't have anything to do with the question. It seems to assume that the natural bounce depends on which edge of the screen the ball would hit if it kept going in its current direction. Do you really think the bounce angle is the same no matter where it hits another ball?
yea, i've tried it. it answered what the question was, “How to make a ball bounce off eachother”, they said they wanted it to be like the “if on edge, bounce” block, so i made the solution.
i needed it like one bounce block with a drop down

Last edited by sullydux (Dec. 25, 2023 11:34:26)

sullydux
Scratcher
8 posts

How should I make a ball bounce off a ball

deck26 wrote:

The line I described will be a tangent to both balls - it forms a right angle with the radius of both circles. So it tells you where the contact point is and is, I think, essentially the same as a flat surface for the bounce calculation.

Never mind

Last edited by sullydux (Dec. 25, 2023 17:37:18)

Powered by DjangoBB