# Collision Response

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

## Recommended Posts

I don't need some complicated collision response, I just need to figure out where will the cars go after collision. For example, two cars are going, one behind another, and the second one goes faster. When he hits the first car, it should continue going, and not go backward (because I'm currently using car.Velocity = -car.Velocity). Also, if they go head-to-head and collide, they should bounce off... So, I need to calculate the new velocity, any ideas?

##### Share on other sites
/*car A: position : Pavelcotiy : Vamass : macar B:position : Pbvelocity : Vbmass : mb*/const float e = 0.7f; // elasticity or amount of bounce. range [0, 1].Vector N = (Pb - Pa); // normal of collisionN.Normalise();Vector V = (Vb - Va); // relative velocity;float vn = V.DotProdcut(N); // velocity along collision normalif(vn > 0.0f) return false; // cars are moving away from each other. no collisionfloat j = -(1 + e) * vn / (1 / ma + 1 / mb); // collision impulse// apply change in momentum to car velocitiesVa -= N * (j * ma);Vb += N * (j * mb);

the simplest I can make it. Just conservation of momentum, A level physics.
boils down to solving a set of equations.

(eq1) va' = va - (j * ma)
(eq2) vb' = vb + (j * mb)
(eq3) ma*va' + mb*vb' = -e * (ma*va + mb*vb);

[Edited by - oliii on October 27, 2007 3:03:40 PM]

##### Share on other sites
Sometimes works, sometimes not... But it's still better than it was :) thx

##### Share on other sites
that should be fairly robust. what's the bug?

##### Share on other sites
Well, I think the bug is that I still can't get the MTD, and therefore because of the collision, in one frame the velocity is calculated ok, but in the other frame it still gets calculated because of the collision and again the velocities are calculated and bounce, but in another direction which still leads to collision... :)

##### Share on other sites
if you overwrite the velocity after the collision, then yeah, you'll get weird behaviour. The collision impulse method implies you are using some rigid body dynamics, which means that the car velocities are derived from forces acting on the car. If you overwrite the velocity directly, say using the current car direction and speed, then it will negate the effect collision impulse.

But then the dynamics of the car are far less straight forward. In any case, you will have to do some very specific physics to get the behaviour you want. My guess would be to disassociate the car physics and graphical represntation, and do some 'hacks' to deal with collisions / skidding.

But the conservation of momentum is accurate in a rigid body simulation context.