Shortest Distance Between two meshes

I’m trying to make magnetism. To do that, I need to find the shortest distances between two objects to apply impulses to. Here’s my problem:
233459-
The black line is what I want. The green line is the distance between the two objects’ ORIGINS and the red line is the distance found by using “closest point on collision” from the origin of one object. I am really stuck and I need help. Thanks in advance.