Used distance formula to do the collision detection