Hi, I'm new at scratch and we have to programm a new project about 2 bouncing balls, which should bounce and collide with real physics. The problem is, I have no idea, how to make such a difficult programm and need your help. Another problem is, we can't use the "step"-order, but the "go to -x,y position" stuff. Here's the link of my programm. Please help me, thank you
--> http://scratch.mit.edu/projects/N3ohunt3r/1364933
Offline
Have a look at my project, physics marble cannon. This might help you a bit. It can be very complicated making a project like that.
Offline
Ty for the answer. But our problem is about a 2 dimensional elastic collision, that means thats more an vectorial problem. A link to a nice picture of our problem is --> http://www.gymnasium-walldorf.de/mathematik/elastischerstoss/elastischerstoss.htm
another problem is the gravity, it has to be a horizontal throw after the collision and we don't know how to solve this problem of calculating with scratch, because we dont know really know the celerity of the 2 balls. Have a look at the our project/ script to get further information, what we mean.
Offline
Look at my project "elastic bounce multiple."
http://scratch.mit.edu/projects/amcerbu/1576239
If you download, the equations are at the very end of the script.
a is obj 1's x position
b is obj 1's y position
c is 1's x velocity
d is 1's y vel.
e is 2's x pos.
f is 2's y pos.
g is 2's x vel.
h is 2's y vel.
i, j, k, and l are the temporary variables for new x, y velocities for objs 1 and 2 respectively. If we use c, d and g, h, there are recursive problems, as the equations near the end will be solving with new values.
Please tell me if this helps.
Last edited by amcerbu (2011-02-05 19:12:58)
Offline
Here's how I got around the problem a while back:
firstly you need to variables (e.g. XV and YV). These can represent and store values for your X and Y velocity. You can now get the ball to constantly change it's X position by XV and it's Y position by YV. Setting the variables to positive or negative values moves the ball around the stage at different speeds. Imagine that the first ball is moving along with an XV of 10 and a YV of 3 and it then collides with the second ball. What you need is an if statement script like this one:
if: touching "ball 2"
set XV to XV * -1
set YV to YV * -1
endIf
By multiplying both variables by minus one, the direction will change as doing this will either change the variable from negative to positive or positive to negative. Once this conversion has occured the ball will be have an XV of -10 and a YV of -3. If it had a velocity in the negative direction already it will be converted to a positive.
Using this you can easily make your ball collide off anything you want (albeit not amazingly accurately as you'll always end up bouncing directly off of the object, angles are not considered.
You might also like to deduct a small amount of velocity after the collision too, so that the collision slows the ball:
if: touching "ball2"
set XV to XV * -1
set YV to YV * -1
if: XV > 0
change XV by -2
else
change YV by 2
endIfElse
if: YV > 0
change YV by -2
else
change YV by 2
endIfElse
endIf
This way the collision will slow the ball down, as you would expect.
Hope this helps
Offline
sparks wrote:
Here's how I got around the problem a while back:
firstly you need to variables (e.g. XV and YV). These can represent and store values for your X and Y velocity. You can now get the ball to constantly change it's X position by XV and it's Y position by YV. Setting the variables to positive or negative values moves the ball around the stage at different speeds. Imagine that the first ball is moving along with an XV of 10 and a YV of 3 and it then collides with the second ball. What you need is an if statement script like this one:
if: touching "ball 2"
set XV to XV * -1
set YV to YV * -1
endIf
By multiplying both variables by minus one, the direction will change as doing this will either change the variable from negative to positive or positive to negative. Once this conversion has occured the ball will be have an XV of -10 and a YV of -3. If it had a velocity in the negative direction already it will be converted to a positive.
Using this you can easily make your ball collide off anything you want (albeit not amazingly accurately as you'll always end up bouncing directly off of the object, angles are not considered.
You might also like to deduct a small amount of velocity after the collision too, so that the collision slows the ball:
if: touching "ball2"
set XV to XV * -1
set YV to YV * -1
if: XV > 0
change XV by -2
else
change YV by 2
endIfElse
if: YV > 0
change YV by -2
else
change YV by 2
endIfElse
endIf
This way the collision will slow the ball down, as you would expect.
Hope this helps![]()
Sparks, I think the question is asking about elastic collisions between circles. Try this document, second and third pages:
http://www.vobarian.com/collisions/2dcollisions2.pdf
For an example of this, look at:
http://scratch.mit.edu/projects/amcerbu/1580333
Offline