I have a driver that is expressed as "var if var<=0.26666 else needsomethinghere". when var reaches 0.26666 in the local space x axis, I would like for else to taper my variable down to 0 once my object reaches .57 on the x axis. If i need to add another variable im fine with it. Just want my object to follow until .26666 and then .26667 all the way up to .57 brings my object back to 0.0 on the xaxis. currently ive placed 0 for else, which jumps it down to 0.0 past .26666. changing i the direction of my driver in the negative x past .26666 is the desired result.
In order to get the value moving back down towards zero once the bound has been reached you simply need to specify an expression that gives the desired result. The key is to think about the boundary cases - in this case, what happens at 0.26666
So, up to 0.26666 you want the output to be
Above 0.26666 you want it to move back towards 0 - so you need to subtract var ie,
-var, BUT, at 0.26666 you want it to equal 0.26666... ie, you want it to be
(0.26666*2) - var
This would result in the expression
var if var < 0.26666 else 0.53332 - var.
You can actually link multiple of these conditionals together so you may want it to stay at zero once it reaches zero. ie,
below 0.26666 :
0.26666 -> 0.53332 :
0.53332 - var
over 0.53332 :
This could be produced with :
var if var < 0.26666 else 0.53332 - var if var < 0.53332 else 0
Nest the ternary expressions
The needsomethingelsehere bit is
a * (a - x) / (b - a) + a if x <= b else 0
which is the linear equation created from two points
(a, a) and
(b, 0) up to
equivalently, could use
max(0, a + a * (a - x) / (b - a))
which will set to zero for any
x > b , if
b > a > 0
Edit just noticed that you stipulated doubled, which would be a matter of substituting
2 * a for
b in equation above, which will reduce it down to.
max(0, 2 * a - x)
Test run in python console for var in one tenth increments from 0 to 1.
a, b = 0.2666, 0.57
>>> for i in range(10): ... x = i / 10 ... print("%3.1f" % x, x if x < 0.2666 else max(0, 0.2666 + 0.2666 * (0.2666 - x) / (0.57 - 0.2666))) ... 0.0 0.0 0.1 0.1 0.2 0.2 0.3 0.237251153592617 0.4 0.1493803559657218 0.5 0.0615095583388266 0.6 0 0.7 0 0.8 0 0.9 0
Suggest using a custom property on some object for
b and using as vars in driver expressions, makes it easier to change the ranges down the line.