I have drivers set up between two Empties as an experiment (before I move on to more complex endeavors), and I want the scale of one Empty to be controlled by the distance between it and the other Empty - in such a way that when the Empties are at their maximum closeness (0 distance) this is the max value (or 1), and when they are separated by a distance of x this is their min value (or 0). How can I set this up?

Two Empties separated by a distance of 1 BU, with a simple driver on the Scale values.

In the image above, the distance from "Empty 2" is controlling the X,Y,Z scale of "Empty 1". However, Empty 1 shrinks when Empty 2 is brought closer - which is perfectly logical, but I want the opposite effect. This would allow for more intuitive rigs to be created where an Empty can be brought closer to an Armature's Bone to create an effect.

There may be cases where I want the min value to be greater than zero, so that Empty 1 does not scale down to an infinitely small size and disappear when Empty 2 is moved away past x distance.

I'm sure there's a way to do this with an expression, but how exactly I do not know. Please pardon my weakness when it comes to math and coding.

I tried a few different expressions involving -var or var*-1, but haven't made much progress.


2 Answers 2


Could use

max(0, 1 - var)

as your driver expression, to have the value at 1 for var = 0, and 0 for var = 1 or more. Could change the 0 to 0.1 (for example) in expression to have a non zero min.

Another take on it would be to use one driver on a custom property on your scaling empty and use the new use_self option of drivers, to pass the empty object (self) to the driver.

A small piece of code to register a function to the driver namespace

import bpy

def e_driver(self, var):
    self.scale = (var, var, var)
    return var

bpy.app.driver_namespace["e_driver"] = e_driver

This driver is then set up on the custom property, which will also set the empties scale.

enter image description here

Added another couple of empties with this set up to your blend.

  • $\begingroup$ max(0, 1 - var) worked perfectly, and it's easy to customize. Thank you! The part about setting up a custom property however, I don't understand. Would you mind explaining more about custom properties and how use_self works? And is that script to be run from the text editor or pasted all into the driver input field? When I open your .blend it says ERROR: Invalid Python expression. $\endgroup$
    – Mentalist
    Feb 7, 2017 at 7:18
  • $\begingroup$ Whoops, I indented script across to paste here before saving blend. In text editor: select all; shift tab to unindent all; then either save and reopen or run script and it will be Ok. Updated blend. $\endgroup$
    – batFINGER
    Feb 7, 2017 at 9:32

Here's the magic formula for the driver:

1.0 if (var <= 0.0) else 0.0 if (var >= <maxval>) else (<maxval>-var) / (<maxval>)

So if I want my max value to be 5.0, then the formula would look like this.

1.0 if (var <= 0.0) else 0.0 if (var >= 5.0) else (5-var) / (5)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .