Ok, the more fun way(Mathematical way :D)
X² + Y² = D²
In other words
DeltaX² + DeltaY² = Distance²
So! Delta means X1 - X2
(or X2 - X1
) but we are squaring it so it wont matter.
we have body A -> A
and body B -> B
and each has a position property so we will do this
var distance = pow(A.position.X - B.position.X,2) + pow(A.position.Y - B.position.Y,2);
distance = sqrt(distance) # Since X² + Y² = Distance² we need to square root it