Jump to content
  • Advertisement
Sign in to follow this  

Collision response

This topic is 1369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I've just implement a collision check method between 2 circles (something really simple tongue.png), now I want a collision response.


I've seen many tutorials that throw formulas without explain their means, but I'm sure I could get a general approach with the mass of the object and the velocity of each objects and some factors for bounciness and friction, but I dont get the way the are related after a collision happened. Do you have a nice way to get a general collision response ?


PS: This is for platformer, but I'm thinking of reusing this kind of physics in an other game ;)


Thanks in advance,


Have a nice day.

Edited by panicq

Share this post

Link to post
Share on other sites

There are several ways to determine a collision response.


One such method is to simulate the physics of the situation, calculating the forces on the two objects. Those forces can be applied to the center-of-mass (or center-of-gravity CG) of each object as linear forces and torques.


Another, perhaps the simplest, method is to merely assume both spheres respond elastically, forget about forces and torques, and set their velocities in the opposite direction Vnew = -Vold, like billiard balls. A sphere strikes another sphere in the direction up-to-the-left and flies off up-to-the-right.


If a more formal collision is needed or desired, the forces on the objects can be done by simulating the compression of the surface of each object (like a rubber ball hitting a wall) taking in account the resiliency or the restitution factor for the object. As an example, consider the situation where your two spheres have collided and they overlap by a distance D. Part of D is the compression of sphere 1 and part is the compression of sphere 2. For simplicity, assume both spheres are the same radius, have collided directly in line with their centers-of-mass, and have the same restitution factor W in units of kg-meters-per-second-squared/meter. Since both spheres have the same factor, the compression of each is D/2. That means that the force on each sphere is W * D/2, in the direction of the center-of-mass. If the collision is NOT in line with the centers-of-gravity, the compression force is resolved into a force through the center-of-mass, and a tangential force which results in a torque.


The force through the center-of-mass is applied using, for instance, Newton's laws - primarily F = m * a (force = mass * acceleration).


In the following the bold letters indicate vectors, as the force and the acceleration are directional.


For F = m * a, the force (W * D/2) and mass are known, so put the unknown (acceleration) on one side of the equation, and the knowns on the other side: a = F/m. The acceleration (in meters/sec2) in this example is W * D/2 / mass (in kg), and is in the direction from the point of collision through the center-of-mass.


The sphere's new velocity V = V0 + a * dT, where V0 is the sphere's (vector) velocity at the time the collision, a is the calculated acceleration, and dT is the time since the last collision check was performed, normally the frame rate of your app. The new position P of the sphere = P0 + V*dt, where P0 is the position of the sphere at the time of the collision, V is the new velocity calcuated above, and dT is the same delta-time used in the velocity calc.


The spheres are then drawn at their new positions P in the next rendering frame. This type of simulation may result in the spheres appearing to overlap (being compressed) for one of more frames if, for instance, the forces are not great enough to separate the spheres in time dT.


Note: this is just one of several methods for handling collision response. Another approach is to calculate an impulse (force) large enough to separate the spheres in time dT. Even that can be done in several ways. For instance, use very large values for the restitution factors and using very small dT values. Alternatively, that can also be simulated using the V = -V example above.


The "restitution factor" mentioned is likely what you mean by "bounciness." Friction is a bit more complicated and would be applied if the velocities of the spheres are not anti-parallel at the time of the collision - i.e., collision at an angle.


In that case, the force on the spheres is calculated in two pieces - one force (a "normal"** force) through the center-of-gravity, and another tangential (perpendicular to the first force) to the surface. The tangential force is proportional to the normal force, the relative velocity of the spheres at the point of collision, and friction factors of the two spheres.


** "normal" is the sense of perpendicular to the surface, not meaning "ordinary."


The tangential force is applied as a torque and an additional normal force on the center-of-mass. The additional normal force is added to the first force (used in F = ma) and the torque (the vector cross-product of the tangential force with the vector from the point of collision to the center-of-mass) results in a change in angular velocity (spin) where torque = MOI * dL/dT. MOI is the motion of inertial (google for it) and dL/dT is the change in angular velocity (dAV/dTfor the sphere. So, dL/dT = torque/MOI. For a very simple response, you can simulate that by calculating angular velocity AVnew = AVold + torque/MOI * dT. The new orientation of the sphere (rotation) ROTnew = ROTold * AVnew * dT. N.B., dT is the same small delta-time used throughout the calculations.

Edited by Buckeye

Share this post

Link to post
Share on other sites

Thank you for the answer, but what do you mean with: "have collided directly in line with their centers-of-mass" ?

Share this post

Link to post
Share on other sites

what do you mean with: "have collided directly in line with their centers-of-mass" ?


The velocities of the spheres are anti-parallel. That is, each sphere is moving directly at the center-of-mass of the other sphere; a "head-on" collision as opposed to a collision at an angle.


When the spheres collide head-on (and they are not rotating), there is no tangential force and friction plays no part. That assumption was to simplify the explanation.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!