I'm writing a really basic collision detection system (AABB vs AABB, AABB vs Circle, Circle vs Circle), and I've just got to the point of writing the actual loop which iterates the objects and checks for collisions.
My question is when do I apply the velocity to each object? Do I move all objects by
vel * dt before I even start colliding? Do I apply the velocity as I iterate? If so, do I apply it to both objects I'm testing, or just the first, and then apply the velocity to the second when I check collisions against that one?
Also presumably I should do the whole collision check recursively (as the act of responding to one collision might cause another), but that obviously effects how and when the velocity is applied.
My suspicion is that I should move all the objects by their velocity before I begin, and then recursively detect and respond to collisions until nothing is colliding (or until some loop limit).