Getting the distance between two objects

Hi there,

I’m rigging a human body now since I’m experimenting now, I’d like to try out a feature that kinda repels or attracts bones. As long as the influencing bones are within a certain distance range, that is.

I’m thinking a driver can get this done and I’ve sort of worked this out in my head but there is one thing that I don’t know how to achieve. That is, the distance between two objects - bones in this case. If I can have that the rest seems doable.

Is there a way to achieve this? Since locations in blender will be in three coordinates, is there a way by which I can get the distance as a single value, say 2 units or 2 meters?

Thanks in advance,

That will be a tricky subject since you have to measure between 2 specific points. If you have 2 3D coordinates then the distance between them is just “(p1 - p2).magnitude” assuming that p1 and p2 are Vector objects.

What that p1 and p2 are is the hard part. Are you trying to find the closet point between the two bones, the distance from the head of one bone to the tail of the other? The distance between the bone centers?

Ah! Thanks, Kastoria!

You raise questions that I never thought of…

I was wondering if blender had a built-in function that found the distance. But this formula would do just fine. Vector algebra is not my strongest points, so what is this magnitude?

And looking online for solutions like this I came across this in wikipedia. This details it as the Euclidean distance between two three dimensional points:

I think the most convenient way would be the distance between the head of the influenced bone and the tail of the influencing bone. But I don’t think it would matter… The distance between the centers of two bones would do just as fine I suppose unless their distance need to be calculated differently that is.

And I’m not sure how I can get the coordinates between the head and the tail. When I’m in edit mode the “Copy Data Path” is greyed out. Is there any other way by which I can retrieve this? Cos I don’t know how else I could retrieve them.

Thanks again for your response,


The ‘magnitude’ of the vector is simply the total length of the vector. If you have 2 points in space (represented as vectors) then the distance between them is the length of the vector between them. So (p1 - p2).magnitude is the length of the vector between the two points and thus is the distance between the two points.