Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How should I make a ball bounce off a ball
- sullydux
-
Scratcher
10 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
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
if on edge, bounceblock?
- nowayoryesway
-
Scratcher
19 posts
How should I make a ball bounce off a ball
maby he meant this (a LOT of blocks here)
when green flag clicked
forever
move (10) steps
if <touching [whatever sprite here] ?> then
set [dir] to (pick random (1) to (4))
if <(dir) = [1]> then
point in direction ( 45)
end
if <(dir) = [2]> then
point in direction (-45)
end
if <(dir) = [3]> then
point in direction (135)
end
if <(dir) = [4]> then
point in direction (-135)
end
end
end
- 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.
Of course this also ignores things like putting spin on the cue ball to affect how it moves.
- sullydux
-
Scratcher
10 posts
How should I make a ball bounce off a ball
do you want to bounce off like theyeaif on edge, bounceblock?
Last edited by sullydux (Dec. 24, 2023 12:04:13)
- sullydux
-
Scratcher
10 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.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.
Of course this also ignores things like putting spin on the cue ball to affect how it moves.
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.
This project https://scratch.mit.edu/projects/174551399/ demonstrates this.
- RethinkingVoxels
-
Scratcher
1000+ posts
How should I make a ball bounce off a ball
simple (kinda)do you want to bounce off like theyeaif on edge, bounceblock?
when green flag clickedput this script in both sprites
point in direction (45) //optional
forever
move (10) steps
if on edge, bounce
if <touching [Ball2 v]?> then
bounce ::custom //run without screen refresh
wait (0.1) secs
end
define bounce
set [last x v] to (x position) //the variable last x needs to be for this sprite only
change x by (9999)
if on edge, bounce
set x to (last x)
Last edited by RethinkingVoxels (Dec. 24, 2023 13:39:21)
- deck26
-
Scratcher
1000+ posts
How should I make a ball bounce off a ball
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?simple (kinda)do you want to bounce off like theyeaif on edge, bounceblock?when green flag clickedput this script in both sprites
point in direction (45) //optional
forever
move (10) steps
if on edge, bounce
if <touching [Ball2 v]?> then
bounce ::custom //run without screen refresh
wait (0.1) secs
end
define bounce
set [last x v] to (x position) //the variable last x needs to be for this sprite only
change x by (9999)
if on edge, bounce
set x to (last x)
- RethinkingVoxels
-
Scratcher
1000+ posts
How should I make a ball bounce off a 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.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?simple (kinda)do you want to bounce off like theyeaif on edge, bounceblock?when green flag clickedput this script in both sprites
point in direction (45) //optional
forever
move (10) steps
if on edge, bounce
if <touching [Ball2 v]?> then
bounce ::custom //run without screen refresh
wait (0.1) secs
end
define bounce
set [last x v] to (x position) //the variable last x needs to be for this sprite only
change x by (9999)
if on edge, bounce
set x to (last x)
- sullydux
-
Scratcher
10 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.thanks
This project https://scratch.mit.edu/projects/174551399/ demonstrates this.
- sullydux
-
Scratcher
10 posts
How should I make a ball bounce off a ball
i needed it like one bounce block with a drop downyea, 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.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?simple (kinda)do you want to bounce off like theyeaif on edge, bounceblock?when green flag clickedput this script in both sprites
point in direction (45) //optional
forever
move (10) steps
if on edge, bounce
if <touching [Ball2 v]?> then
bounce ::custom //run without screen refresh
wait (0.1) secs
end
define bounce
set [last x v] to (x position) //the variable last x needs to be for this sprite only
change x by (9999)
if on edge, bounce
set x to (last x)
Last edited by sullydux (Dec. 25, 2023 11:34:26)
- sullydux
-
Scratcher
10 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.
Never mind
Last edited by sullydux (Dec. 25, 2023 17:37:18)
- Discussion Forums
- » Help with Scripts
-
» How should I make a ball bounce off a ball