Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Collision Results.  Deflection, Force Transfer, Torque

Posted on 2009-04-11
Medium Priority
Last Modified: 2013-12-26

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!

Question by:recruitit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5

Author Comment

ID: 24136066
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.

Author Comment

ID: 24136166
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.

Author Comment

ID: 24136185
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.

Author Comment

ID: 24136376
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.

Accepted Solution

recruitit earned 0 total points
ID: 24136438

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question