
Here's what I have so far
http://www.geocities.com/sfpiano_uvi...lCollision.swf
however, the collisions with the ball and the paddle are really bad. As of now all I have is the ball just reverses its direction as if it hit one of the walls, so the ball usually doesn't go the direction it should.
Code:
if (_root.ball.hitTest(_root.paddle)) {
speedy = (speedy)*1;}

Gross Pecululatarian
Okay, I've lot the links to the individual threads, but here's the bouncing info from this forum:
 Simple Method (Unsure if it works 100%):
R = 2W  P
P = balls path
W = walls angle
R = reflection
All angles must be in range of 0360
 Rotating method:
// get the position of ball in relation to wall
x = ball._xwall._x;
y = ball._ywall._y;
// get angle in radians of wall
angle = wall._rotation*Math.PI/180;
// rotate the scene to make it as if wall was lying flat
// angle is the amount we need to rotate it.
// first rotate ball's position:
x1 = Math.cos(angle)*x+Math.sin(angle)*y;
y1 = Math.cos(angle)*yMath.sin(angle)*x;
// then the velocities
vx1 = Math.cos(angle)*vx+Math.sin(angle)*vy;
vy1 = Math.cos(angle)*vyMath.sin(angle)*vx;
// now check if ball is below wall
if (y1>0ball._height/2) {
// set it at the edge of the wall
y1 = 0ball._height/2;
// reverse the y speed, and lose a little momentum
vy1 *= .9;
// convert new positions and speeds back to world coords
x = Math.cos(angle)*x1Math.sin(angle)*y1;
y = Math.cos(angle)*y1+Math.sin(angle)*x1;
vx = Math.cos(angle)*vx1Math.sin(angle)*vy1;
vy = Math.cos(angle)*vy1+Math.sin(angle)*vx1;
ball._x = wall._x+x;
ball._y = wall._y+y;
}
 Some Info on gravitational force, and billard ball physics:
OK, I have not posted much on here, but I am an undergraduate engineer, and I just studied collisions in physics, so I may be of some help.
All collisions are is a transfer of "momentum". People misuse words everyday, so momentum can be defined as
p = m * v
where p is momentum, m is the mass, and v is the velocity.
V(velocity) is a vector quantity which means not only does it have a magnitude (number), but it also has a direction. This means the p (I will refer to momentum as p for the rest of this post) also must have a magnitude and direction.
Now onto collisions. There are two types of collisions: inelastic, and elastic. In an inelastic collision, the two objects stick completely together. In an elastic collision, the two objects do not. Elastic collisions are obviously the type between two billiard balls.
It is a fundamental law that in an elastic collision (which is also one with no outside forces), linear momentum is conserved. This means that the momentum before the collision must be equal to the momentum after the collision. Now onto some fundamental equations. These are the equations for a two object elastic collision where
m1=mass of object 1m2=mass of object 2v1=velocity of ball 1we are assume right now that object 2 is stationary.
final velocity of ball 1= ((m1m2)/(m1+m2))*v1
final velocity of ball 2= ((2*m1)/(m1+m2))*v1
Looking at these equations, one can see that if the two objects are of equal mass, then the final velocity of ball 1 will be "0" where the final velocity of ball 2 will be the initial velocity of the first ball.
You may be thinking to yourself, "But I have played pool before, and the cue ball still have a small velocity on it after hitting another ball." This is because of two reasons. The first is simply that the cue ball is actually a fraction bigger than all of the other balls. This mostly helps commercial ball returns. If you look at the equations, you will see that the final velocity for object 1 if it is just a little bigger than object 2 will be very small. Lastly, the collision is not completely elastic. No collision will ever be completely elastic because the balls bend in a little on contact. You can't see it, but they do, and that absorbs a tad of the momentum.
Now, what if the second ball is also moving? This is where it gets difficult. If the balls are rolling together, do you have to use one equation: m1*v1 + m2*v2 = (m1+m2)V
But if they aren't, you have to use a different equation. What I would do is to think of the balls hitting like this: During the split second that the balls are actually touching, think of one ball as being stationary and being hit by the other ball. Then when you find the final velocity of that, just add it to the actual initial velocity. On top of that, you will need to find the components of the velocities and add them up seperate. For example, a ball that is moving at 10 m/s at an angle of 40 degrees from the horizontal has a xvelocity of 10*cos40, and a yvelocity of 10*sin40. That is about the best I can do with two balls moving at once.
The angles that they hit is important too. The final angle that they rebound at is equal to the angle that they actually hit. You can find this angle by doing the following:
arctan(y/x) which is the inverse tangent function of the change in y divided by the change in x. Example, if you have a ball that's center is at the point (0,0), and it is hitting another ball whose center is at (3,1), first you would find the change in X and Y. the change in Y would be (10)=1, and the change in X would be (31)=2. So the angle between the two would be the arctan(1/2), which happens to be about 26.6 degrees. Now when these two balls hit, ingoring velocities and concentrating on angles, you can see that the ball being hit will go off at an angle of 26.6 degrees, while the first ball doing the hitting will go off in the exact opposite direction, which is either
26.6 degrees, or 333.4 degrees.
I won't go over it, it will take too long, and this is already a quite long post, but combining those last two methods, the first of finding the magnitudes, and the second of finding the direction, you should be able to make some pretty realistic collions. Obviously, you will want to apply a friction constant, otherwise the balls will go on forever and never stop.
Also, there is one other collision, and that is with the ball and the rails. Obviously, most people know that it just kinda changes directions. If the ball is traveling upwards, and hits the right rail, the yvelocity will remain exactly the same, and the xvelocity will just inverse, for example initially a ball has xvel=2, and yvel=5, when it hits the rail, it will have a yvel=5, and a xvel=2. To be more realistic you can add an effect that takes the velocity down just a tad when it does hit. But that must be quite small.
Well, that is about all I have time for right now. I hope this helps someone, I tried to put thought and time into it. Enjoy people

ism
ed,
that is the most understandable explanation of collisions i have EVER read! and i've read a few. great work!
thanks
BlinkOk

this didn't work for me. When I tried it out, all that happened was the ball just stuck itself in the top wall and didn't move.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
