This is a simplified example which I wish to apply to a more complicated animation situation.

I have a cube, that is 1x1x1 in size, origin at the centre and is located at (0,0,0). It sits atop a plane with the origin of (0,0,-0.5).

I want to use drivers to drive the cube's X and Z coordinates when I change its Y rotation so that the cube does not pass through the plane. Like so:

Cube 1 Cube 2

I know the X and Z locations can be calculated using cos and sine but I'm having trouble figuring out the equation for the drivers.

Thanks for your assistance.


1 Answer 1


This could be a math question, but since we are using Blender we could use drivers tools, f-curve tools and empties.


Even though the objects center is at XZ (0, 0) the center of the first half rotation is at (1, -1).

enter image description here

We will need the trigonometric functions sinus and cosinus to get points on a circle.

enter image description here

Note that the object center and the center of revolution do not have a distance of 1. We will have to calculate the distance with the pythagorean formula.


a**2 + b**2 = c**2

The are the relations of sinus cosinus and the angle. Since the values only apply to a circle with the radius of 1, we need to multiply if by the actual radius of the circle.

enter image description here

Setting up the drivers

  1. Add an empty. (This is necessary, because of how Blender editing interface works. If the rotation drives the location, Blender 3D Viewport editing rotation control behaves unexpectedly.)

  2. Add a driver to the Y rotation of the cube.
    enter image description here
    Set the empty's Y rotation as the input. Use world space.
    enter image description here

  3. Add a driver to the X and Z rotation, use the same settings.
    enter image description here

  4. Add the basic trig functions as the expression.
    enter image description here

    X Loc: cos(var) Z Loc: sin(var)

Our cube now move in a circle based on the empty's rotation.
enter image description here

Refining the expression.

Now we can work on the expressions. The Y rotation is negated (clockwise rotation results in positive values). Let's negate X Loc.

X Loc:    -cos(var)

Our cube revolves in the correct direction.
enter image description here

Next, offset the value to make our cube's center rotate around XZ (1, -1). The first center of revolution.

X Loc:    -cos(var) + 1
Z Loc:    sin(var) - 1

Currently, the cube revolves from 0° to -90°, with an input from 0° to 90°. (Marked red)
We need to offset the rotation, resulting in -45° to -135°. That is an eighth of a circle. A circle measure 2 * pi.

1/8 * 2 * pi = pi / 4

Add this to the var in both trig functions.

X Loc:    -cos(var + pi/4) + 1
Z Loc:    sin(var + pi/4) - 1

Now adjust the radius of the circle. Our distance is calculated using the pythagorean formula.

enter image description here

1**2 + 1**2 = c**2
c = sqrt(2)

Multiply the trig calculated offset with the distance c.

X Loc:    -cos(var + pi/4)*sqrt(2) + 1
Z Loc:    sin(var + pi/4)*sqrt(2) - 1

The cube describes the desired rotation perfectly.

enter image description here

Adding a cyclic offset

For the X and Z Location it would be beneficial to have a cyclic input. The span of 0° to 90° from the empty should be repeated. I am going to use the modulo operator to do that.

var%2    ...    rest of var / 2, x in [0, 2[
var%(pi/2)     cyclic for every quarter of a circle, ranging from 0° - 90° (in radians)

enter image description here

The result is cyclic, albeit without an offset.

X Loc:    -cos(var%(pi/2) + pi/4)*sqrt(2) + 1
Z Loc:    sin(var%(pi/2) + pi/4)*sqrt(2) - 1

enter image description here

Finally, let's add the offset to the X Location. Every cycle of 90° we have to add 2 to all X Location values.

First, isolate the cycle of 90° (pi/2) using the floor() function. Then multiply the result by 2.

x = floor(var / (pi/2)) * 2   #
x = floor(2*var / pi)*2       # one step simpler/prettier

Add this to the existing X Loc expression.

X Loc:    -cos(var%(pi/2) + pi/4)*sqrt(2) + 1 + floor(2*var / pi)*2  
Z Loc:    sin(var%(pi/2) + pi/4)*sqrt(2) - 1

Getting things more production ready

Add a floor plane on (0, 0, 0). Move plane (0, 0, -1) in edit mode and scale it accordingly.

Lock the X and Z rotations on the empty.

Parent the empty and the cube to the floor plane.

Looking good!

enter image description here

  • $\begingroup$ A very detailed and helpful answer which I very much appreciate. $\endgroup$
    – BlenderBro
    Commented Dec 23, 2016 at 15:10
  • $\begingroup$ How could you modify the formulas so the side length is variable? $\endgroup$
    – timeslidr
    Commented Sep 18, 2022 at 0:11

You must log in to answer this question.

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