Original Post
Hey, I wrote a small physics engine for my 2D car racing game, but for unknown reasons it often doesn't run correctly. You can download it here : http://zone51da.free.fr/physikv2.zip (wait a few seconds before moving the car) As you can see, when there is a collision the cars often stick themselves, an aberrant collision response is calculated and I don't understand why. But perhaps you will understand after my explanations : //Car movements I use 4 forces to move the cars : - Propulsion force - Air friction - Left brake (for turning) - Right brake These forces are applied to the car center to create an angular momentum (with the famous crossproduct formula). Then I integrate the result to determine the velocity and I integrate again to determine the car position and the car angle. //Collision detection If a car1's vertex is into the car2's polygon, or conversely, the engine will detect a collision. This algorithm is efficient but the second step, side contact detection, is less obvious : I select the side which is nearest of the vertex contact and I memorize the distance (called dist) between this side (called cSide) and the vertex contact. //Collision response I noted that adding the vector R to the current velocity is sufficient to compensate the velocity component in cause of the collision. R = normal(cSide)*dotproduct(normal(cSide),-current_velocity) i.e, the projection of the velocity vector on the cSide normal. Or R' = (1+E)*normal(cSide)*dotproduct(normal(cSide),-current_velocity) where E is a rebound coefficient. Thus the new velocity is : V(t) = V(t-1) + R So to calculate the reaction force RF after a collision, I use the acceleration definition : RF = m * acceleration = m * dV/dt = m*(V(t) – V(t-1))/dt = m*R/dt RF = m*normal(cSide)*dotproduct(normal(cSide),-current_velocity)/dt I try to take into account the parameter dist but the results are not better. Any idea ? [Edited by - Orwin on March 24, 2006 5:24:46 AM]