After adding drivers to rotate the wheels when a car model is moved the wheels at one side of the car rotate clockwise (CW) but the wheels on the opposite side rotate counter-clockwise (CCW).

I want to animate the car and the wheels should move independently from the direction of movement. I first tried to use the distance to an empty like this, but it this leads to the CW/CCW problem. Changing the sign of the rotation would probably fix this, but it seems that there isn't an option for changing the sign of the driver value.

enter image description here

A scripted expression tested in the console window:

>>> print(bpy.data.objects['Mazda'].location.y)

Doesn't work in the script input field:

enter image description here

What format does Blender expect here?


It expects to not use direct data path but to use a variable like this:

enter image description here

The reason is for update purposes. With variable the driver knows what his dependencies are thus it knows what value to watch. Watching the whole bpy.data for changes is not efficient.

Here are examples what is allowed in the Expr. field. You can use number expressions with driver variables plus some build-in functions like sin, cos, min, max, frame, etc.(to see all of them put bpy.app.driver_namespace[' into console and hit Ctrl+Space)

You can also use custom python functions, where you can access bpy.data, but you need to add such functions to driver namespace first:

import bpy

def mazda_loc_y_func():
    return bpy.data.objects['Mazda'].location.y

# add function to driver_namespace
bpy.app.driver_namespace['mazdaY'] = mazda_loc_y_func

In the Expr. field you just type mazdaY(). Without the driver variable the driver might not update nicely though.

  • $\begingroup$ Thanks for this excellent answer, how would a custom python function be invoked, it looks that it should run once for registering the function in the driver namespace. $\endgroup$
    – stacker
    Dec 22 '14 at 9:48
  • $\begingroup$ Yep you need to run the code once in text editor and then you can use such function with drivers $\endgroup$ Dec 22 '14 at 9:51
  • $\begingroup$ Very well written answer. $\endgroup$
    – David
    Dec 22 '14 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.