# Collision Results. Deflection, Force Transfer, Torque

Hello

I am currently at a stage in developing a game (a more advanced pong) where I want to start making the objects in the game behave more like real world objects.

I want to put some free moving obstacles in the game that the ball can collide with.  I wanted to have this "equation" for just the plain ball/wall/paddle collision, but I ended up using the x,y velocity trick where you invert the x,y velocity depending on which object the ball collided with.

What I am looking for, and I just havnt managed to find the right explation/equation, is two things.

A.)  When a collision happens, finding the angle of which the ball should bounce away from the object collided with. (The reason I need a more advanced approach is that the free moving objects can obviously be rotated to any degree and not just the vertical/horizontal position).

B.)  Working out how much force needs to be transfered into angular momentum/torque.

I am going to start with a rectangular object, and a round or square ball.  It seems to me that, logically, the further the ball hits to the edge (lengthwise) of the rectangle, the more force will be transfered to torque, rather than normal x/y velocity.  Althought im sure this will also be modified by the angle of which the ball has collided with the rectangular object.

I suppose to make it simple, I need "two?" equations.

One for finding the angle(or x,y velocity) that the ball will travel after colliding with a free moving object.

The other for determining the amount of force transfered to each objects torque.

I can imagine that this could get quite complex with different shape objects, I just want to get my foot in the door with some clear equations to get some practice with.

Appreciate it!

Thanks
###### Who is Participating?

Author Commented:
0

Author Commented:
I think I have managed to figure out part of this.

After making several sketches it occured to me that there was a pattern I could utilise.

In theory if you take a rectangular object and lock it on a 90 degree rotation starting at 0 degrees (horizontal in the case of radians).  Then you can flip the rectangular object 90 degrees and each time you will get either a complete x velocity reversal or a complete y veolicity reversal.

So it occured to me that there is a transition from complete x velocity reversal to complete y velocity reversal, so, reading between the lines, it makes sense that in between these total reversals (inbetween 0-90 degrees, 90-180, 180-270, 270-360, etc) then we would see both x and y velocity reversals or at least deflection.

It would be logical to assume, since at 0 degrees of rotation 100% of the x velocity is reversed and 0% of the y velocity is reversed, that if we take, in this particular case the value of the rotation between 0-90 degrees as a percentage of the 90 degree total, then we essentially apply velocity reversals to the x and y velocities based on that percentage.

So far this is my best guess on this formula.

At 0 degrees X = 0% Y = 100% (Velocity reversal)

At 45 degrees X = 50% Y = 50%

Lets take object A with an X,Y Velocity.

We need to find the line of collision, given two points.  Once we have the line and the lines angle of rotation, we need to calculate which side of the line was collided with, which is easy enough to do by checking the two points on the line and the origin of the colliding object (This is needed so we know if we need to subtract or add to the x,y velocities).

We then take the X,Y velocities of A, multiplied by 2 and the % that we got from the previous angle calculation.

Reaction Velocity(Angle) = ((A.X) +- (2A.X*%)),((A.Y)+-(2A.Y*%))

It just occured to me that this might only work if the ball is moving in perfect angles.... im not so sure now, ill need to test it and ill be back with the results.
0

Author Commented:
Thinking it over, the angle of objects A's traversal is already applied in the formula.

Just to clear this up.

Px = Percentage of X Reversal (Based on the % obtained from the % of rotation)
Py = Percentage of Y Reversal (Based on the % obtained from the % of rotation)

As an example, Lets take a rectangle, rotated to 157 degrees.  At 90 degrees we have a total x velocity reversal, so from 90 to 180 we are transitioning from total X to total Y.  So we are starting with the base values of 100% X, 0% Y.  So our first calculation is.

[Px = 100 - ((RotationDegrees/NextAngle)*100)]
Px = 100 - (157/180 * 100)

[Px = ((RotationDegrees/NextAngle)*100)]
Py = (157/180 * 100)

Now to get the end velocity of object A colliding with this rectangle, we use the percentages calculated above and apply them in the following calculations.

X Velocity of Object A(After collision) = A.X +- (A.X * 2 * Px)

The reason why I am using the *2 here is because if you can image in a normal pong simulation where the X velocity is reversed, say for example we had an X velocity of 5, when we reverse this velocity we get -5, so 100% of X reversal here is 10 e.g. 5 x 2.  Its going to be important to make sure that you either add or subtracting depending on what values you currently have.

And again for the Y Velocity

Y Velocity of Object A(After collision)= A.Y +- (A.Y * 2 * Py)

I havnt tested this yet, but I am pretty sure this is going to work.
0

Author Commented:
Now I just need to sort out angular velocity, elasticity, intertia, velocity transfer, mass, weight.

Whatever, no problem :o)

If I get these done soon ill post the answers back here.
0

Author Commented:
I think theres a problem with this formula.

An object with an x,y velocity of 5,5 colliding with an rectangular object with a rotation of 315 degrees (45/90) results in 50% x and y reversal.

Which is basically 5 - (5 * 2 * 50%) which results in 0 which it should be -5.

Im missing something in the calculation, not sure what it is yet.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.