I have an object with keyframes on its Z-rotation so it rotates about its vertical axis. I want to have a driver on its X-position that takes the Z-rotation value, performs a modulo-operation on it to bring it into the interval [0°, 120°), and then sets the X-position according to this piecewise definition:
If(
0° ≤ var < 60°, 1 / 2 - 1 / sqrt(3) cos(var - 30°),
60° ≤ var < 120°, -1 / 2 + 1 / sqrt(3) sin(var)
)
I figured out how to add a driver to one property and how to add a reference to another property, but I can't get it to work with a conditional statement inside the driver. The expression (1/2)-(1/sqrt(3))*cos(var-pi/6)
on its own works as expected, as does (-1/2)+(1/sqrt(3))*sin(var)
, but if var < (1/3*pi): ((1/2)-(1/sqrt(3))*cos(var-pi/6)) else: ((-1/2)+(1/sqrt(3))*sin(var))
leads to the error message "Invalid Python expression".
This is my first time using Python, so I might just be misunderstanding the Python documentation on IF statements. Is it possible to get this working? Or are conditionals not allowed in drivers?