# Predicted position collision impulse

## Recommended Posts

Finalspace    1147

Hi there,

i have a particle simulation which uses predicted position to compute the contact points which are instanly solved using a simple projection method right now. This works fine, but there is no bounce or friction at all, but its much more natural if there are at least some sort of bounce and friction and thats the part i am trying to figure out. Unfortunatly the methods i know does not work very well, there is no change at all or the result is invalid, like the particles are falling through the ground or something like that, or is not change at all.

Does anyone know how to deal with restitution and friction in simulations which uses the "predicted position" and "previous position" on every frame for solving the collisions? It looks a bit like verlet integration, but its not the same.

Here is the code for projection the particles against some fixtures - in this part just a circle fixture:

CircleShape circle = (CircleShape) shape;
Vec2f circlePos = new Vec2f(bodyPos.x, bodyPos.y);
Vec2f d = predictedPosition.sub(circlePos);
float lenSq = d.lengthSquared();
float len = (float) Math.sqrt(lenSq);
Vec2f n;
if (len == 0) {
len = 1;
n = new Vec2f(1f, 0f);
} else {
n = d.div(len);
}
float penetration = len - radiusSum;

// TODO: Calculate velocity impulse for particle
// Vn = N * (V dot N)
// Vt = V - Vn
// Vec2f Vn =  n.mult(v.dot(n));
// Vec2f Vt = v.sub(Vn);

// Calculate final projection point
}


I have a buffer of prediction position and a buffer of last position.

The prediction position are calculated at the start of the simulation to simply force integration like this:

int index = activeParticles[i];
velocityBuffer[index] += forceBuffer[index] * particles[index].invMass * DT;
predictedPositionBuffer[index] = positionBuffer[index] + velocityBuffer[index] * DT;



And of course the final velocity is re-calculated after the simulation like this:

velocityBuffer[index] = (predictedPositionBuffer[index] - positionBuffer[index]) / DT;


Does anyone have some idea?