Simple Bounding Sphere Calculations for 2d game with p1.x = 100 and p2.x = 200 then dx = 100-200 = -100. Using the formula distance_x = sqrt(dx*dx) we have distance_x = sqrt(-100 * -100) = sqrt(+10000). So, distance_x = 100. You are multiplying two negative numbers, so the result is always positive.