   n00b Problem with Distance Calculate (Using OpenGL, glut)
  Hello everyone,Recently, I have made my first glut 2d game, but have some problem with distance calculation.I want 3 turret on the screen, and they can shoot bullet, when these bullet hit the object, then calculate something like HP of the object or so; and when the object hit the turret, calculate HP of the turret.But while I running the game, I find that bullet just "flying over" these objects, objects' HP do NOT change at all, so does the turrets.At first I wrote following:  float X = Xa - Xb;   float Y = Ya - Yb;   return squrt(X*X + Y*Y); // If this value <= 15.0, then calcu HP...Then it was changed to:  const int Step = 10; // Split 1 Frame to 10 "Sub-Frame"  float MIN, TMP;   float X = Xa - Xb;   float Y = Ya - Yb;MIN = sqrtf(X*X + Y*Y);for (int i = 0; i <= Step; i++)   {  X += (float)i/(float)Step * (Vxa - Vxb);  Y += (float)i/(float)Step * (Vya - Vyb);  TMP = sqrtf(X*X + Y*Y);  if (MIN > TMP) MIN = TMP;   }   return sqrtf(X*X + Y*Y); // If this value <= 15.0, then calcu HP...However, the problem still exist...Did anyone here met this problem before? Thank you for your Reply!   
  Your first attempt correctly calculates the distance between two objects, if one object is (Xa,Ya) and the second object is (Xb,Yb). However, that method (as you appear to understand) may easily miss cases where the bullet only passes briefly within 15 units.I'm assuming your second attempt is to subdivide the path into smaller increments to see if a "collision" occurs between frames. However, even not knowing what Vxa, etc., means, it appears you just keep making X and Y larger and larger, and you don't use MIN and TMP anywhere in that calc.To begin with, to make sure that your logic is correct (including the rest of your code), you might try setting the speeds to something small (much less than 15 units per frame) and see if your first calc works correctly. If it doesn't, the problem may be elsewhere in your code.If you want to be accurate, however, it might be better to calculate a vector for the bullet's direction and test whether the bullet's position + direction*speed*frameTime intersects with the circle around the turret.   