HELP! Collision Detection: NOT WORKING?

Hi,

I'm attempting to create a collision detection algorthm however it fails even though it seems logical to me:

Code :

void Collision_Detector()
{
for (int i = 0; i < particles.size(); i++) // Get the individual particle in the vector (P1)
{
for (int c = 0; c < particles.size(); c++) // Use the all other particles in vector and check if they collide with the particle (P1)
{
if (c != i) // EXCEPT from itself
{
if (particles[c].x == particles[i].x) // Check if particle (P1) and the other particles are in the same X axis direction
{
float distance = particles[i].y - particles[c].y; // IF SO calculate vertical distance from each other.
if (distance < 0.50) // If the distance is greater than 0.50 show messagebox
{
MessageBoxW(0,"Collision Detected","Great!",MB_OK);
}
}
}
}
}
}

The above algorithm makes perfect sense yet it fails to work and it shows message box everytime I create particle in the same X axis location even when the both Y axis are like 200.00 distance away. Why is this can someone help?

Capt.Yoda
Try this:
Remove this test:
if (particles[c].x == particles[i].x)
With it you need the x coordinates to be equal to have a collision.
You should use the formula: c = squareroot[ (xa-xb)² + (ya-yb)² ]http://www.mathsisfun.com/algebra/di...-2-points.html
Same thing.Faster.No abs.