Suppose I have N moving balls of radius r in a 2D space. For simplicity, N < 30.
I want to know the fastest way to check if these balls are colliding every frame.
I could obviously do something like this:
for(int i = 0; i < N - 1; i++){
for(int j = i + 1; j < N; j++){
if (dist(ball[i], ball[j]) <= r) CollisionList.Add(i, j);
}
}
But as this is O(N²) and I want to do this every frame, I'd like to ask if there is a faster way. Every frame I want to be able to deal with every collision and compute its consequences.