Qbasicnews.com

Full Version: Poll(ball to ball collision) physics. Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I need some stuff related to ball collision physics. I don't want to reval more.

Basicly I want to code corect ball collision of two moving balls.

Let's say I have two ball variables declared. Ball1 and Ball2.
They have their own X and Y inertia. I want them to move according to X and Y inertia not according to some angle and speed. That's wrong by my opinion. And it wouldn't work good in my....project...cause...I have different kind of control concept. Khm...

Anyway Ball1 is moving toward Ball2 with Ball1.XInertia and Ball1.YInertia and collides with it. Ball2 can be static or also moving with it's own inertia(Ball2.XInertia and Ball2.YInertia).

Now, I know some things related to collision. Like that Ball1 passes it's inertia to Ball2 and vice-versa but I don't think that it always works like that. I mean what happens when Ball1 only burshes Ball2, changes a direction a bit and passes a part of inertia to Ball2. Am I wrong? Can you help me with this? How to code that?

The ULTIMATE ball to ball collision. I need it!

Thank you.
What i would recommend is to add the components(xv1 and yv1 to xv2 and yv2) of your vectors and it would go to the direction you wanted.

Are you making a billiard game?

If so I'd go with angles. Then give each ball hotpoints for collision. So if ball one collides with ball2, you could just get the both angles, derive the vectors and add em. ;*)
It's not a billiard game. X and Y inertia are basicly X and Y speeds. I just call them inertia cause...well....the friction and stuff.

What do you mean "hotpoints for collision"?

I was naive enough to think that the problem can be solved with one formula. Stupid me.
well take this as an example:


Radius=10
For A=0 to 359 step 5

Ang!=A *3.141593/180
Ball(A).X=Cos(Ang!)*Radius
Ball(A).Y=Sin(Ang!)*Raidius

Next A

the Step thingy is the increment of your hotspots.

All you have to do is:

if BallCollide
For I=0 to 359

If (Bx+Ball(I).X,by+Ball(I).Y) =Inside Ball2 then
Get angle
Add vectors
End if
Next

End if




Next I
Each ball has a mass "m", and a velocity V: Vx and Vy (two dimensions).

The basic formula in shocks are that the "movement quantity", ie the vector (m.Vx,mVy) and the kinetic energy 1/2.m.V^2 are unchanged after the shock:

Before the shock:
1st ball : (m.Vx0,m.Vy0)
2nd ball: (0,0) (for example)

After the shock:
1st ball : (m.Vx1,m.Vy1)
2nd ball: (m.Vx2,m.Vy2)

with:
m.Vx0=m.Vx1+m.Vx2
m.Vy0=m.Vy1+m.Vy2
1/2.m.(Vx0^2+Vy0^2)=1/2.m.(Vx1^2+Vy1^2+Vx2^2+Vy2^2)

Then, to get a fourth equation that will aloow solving this four variables system, you assume some symetry between the vectors...

Do not forget that the velocity of the balls is decreased by the pool's table, to get a realistic movement.

I did not do that for a long time... hope that helps !
Thanx guys. I'll try all of this.

I LOVE THIS COMMUNITY!!!

Edit : After taking a peek on Glenn's routine Lachie wants to worship him.
All right, I will try to help, but I don't necessarily remember this stuff well.


First of all, as far as calculating the actual vectors representative of the velocities of each ball after the collision, you don't need "hot spots." Each ball can be seen as an infintessimaly small point with all the mass of the ball located at that point.

Next, you need to decide whether your collision is going to be elastic or inelastic, basically whether or not the balls bounce off of each other perfectly. I would go with elastic because it makes the calculations easier.

So here are the equations you need to perform the calculations:

mv(x1)initial + mv(x2)initial = mv(x1)final + mv(x2) final
mv(y1)initial + mv(y2)initial = mv(y1)final + mv(y2) final
1/2mv^2(x1)initial + 1/2mv^2(x2)initial = 1/2mv^2(x1)final + 1/2mv^2(x2)final
1/2mv^2(y1)initial + 1/2mv^2(y2)initial = 1/2mv^2(y1)final + 1/2mv^2(y2)final

hope that kinda makes sense, if not ask, and I will try to explain it better.
Glenn's routine pretty much solved most of the problem. But it didn't featured a routine which determins the point of impact so I had to do it like Eric explained.

I tested it and it works fine. Angle of point of collision is determined with plus/minus 10 degrees mistake but it all depents how much STEPs you want in the loop which goes throught all 360 degrees and looks for point of collision.

But there is one big problem. Balls when collide stick one on another. You see, I have to make two colliding balls as solid bodies so that they don't end up one pasting over another. And the collision routine doesn't solve that issue completely. Despite it balls can enter one another due many factors, like field boundaries and imperfection of collision detection. So when the balls collide I need to restore their old positions and then initiate collision routine. In most cases balls stick one on another. They can unstick in most of cases but it ruines the gameplay. It's not fluid like it supposes to be. I need to tweek it and see what can be done but I don't know. If I'm unable to make the collision completly fluid and balls solid as rock...I'll give up.

Whatever happens I need help on this. How to derivate angle of movement from X and Y speeds of a body? In all quadrants. I don't think it's that simple since QB has some imperfections there. Like lack of arcus function.

Thanx.
do you have each ball move one pixel, or zero pixels, every step? That way you can detect if a ball has touched another, immediately.

If you don't do this, collision detection will not always work, since a ball goes inside another ball. Realizes collision. Reverses direction. Next frame, it is still inside. Reverses again. Ad infinitum.
Pages: 1 2 3