Constrained Mechanics

by Malefico


When animating characters in Blender we work defining several "poses" in time changing the position of arms, legs, tentacles or ears following our inspiration.

However if we are trying to animate a machine or the pieces of a mechanical system this approach is not adequate. Imagine for instance animating the crankshafts of a locomotive, we should do it in a way that the wheels were impulsed by the turn of the crank in accordance to the crankshaft movement, not as if they were totally independent pieces. This is something that cannot be done right by the pose-after-pose method.

In this tutorial I'll try to explain how to use Blender "Constraints" to solve some simple mechanisms. More complex stuff could be solved applying the principles outlined here.

It was Caronte the first one in explaining this Blender feature to me, so thanks mate !.

WARNING: This tut requires some basic knowledge about Blender features and common operations which will not be explained in the text. To follow the tut you will need at least version 2.22.

Some theory (a lil' bit)


A crankshaft is a very popular piece in mechanical machines. Its function is to transform a circular movement into a linear one and viceversa. The crankshaft is normally attached to a wheel by means of a piece named crank by one of its edges.

The other edge of the crankshaft is restricted in movement by means of another crankshaft, a slider or any other piece that fits the purpose. When the crank spins the crankshaft transmits only the component of the movement that is colinear to the constraining part.

We will see step by step how to recreate this behaviour in Blender in a way that we will only animate one part of the mechanism (eg. the wheel) and the other parts will be automatically animated by Blender itself.

Mechanics in Blender


Start a new scene in the usual way and select front view. Add a cylinder in this view. No matter how many vertices or size. This cylinder will be our wheel. Name it "wheel" or if you like spanish "rueda" as in the pictures lines down.

Move the cursor some point within the cylinder's edge but far from the center. Add an empty (I would name it "Empty0", do you agree ?). One nice thing you might prefer is that objetcs automatically snap to the grid. To do this just set the GrabGrid option in the Blender userīs panel. We should have something like this:

Now move the cursor to Empty0's location and add a plane (always front view) . Scale it to the left some units till have something like the picture. This will be our crankshaft so name it "crankshaft-1" or again "Biela1" if you feel exotic.

Most important thing is to have in mind that the center of the plane (the one indicated by a pink dot by Blender, not the geometrical center) should be located where it is in the picture (Empty0's location). This should be this way because the rotation axis of the crankshaft will pass by this point. If you don't believe me, grab it and rotate it a little bit.

Now move the cursor to the other edge of the crankshaft, add another empty (Empty1) and parent it to the crankshaft.

At Empty1's location add a new plane. Scale it to form a new crankshaft (see picture). "crankshaft-2" would be a nice name for it. Move the cursor to the central zone of this new crankshaft and do a "CentreCursor" (Edition Buttons) .

If you grab it and rotate it, the crankshaft should spin around its new center (which by now is the cursor location, ok ?). Move the cursor to one edge of the crankshaft2 and add a new empty (Empty2). Parent the empty to the crankshaft.

Things should look like this:

The idea is that both crankshafts will be joined together using this points (Empty1 and Empyt2) like an articulation.

Crazy Constraints


Select crankshaft-1 and go to the Constraints buttons (the chain icon). Add a Copy Location constraint and write Empty0 in the OB box. Try rotating the wheel cylinder in front view. You'll see how the crankshaft-1 keeps paralel to X axis while following Empty0 rotation. Perfect.

Now we're going to try that crankshaft-2 points towards Empty1. To do this select crankshaft-2 and add a TrackTo constraint. Write "Empty1" in its OB box. It may happens that in this moment the crankshaft assumes a funny position. To solve this problem go to the Animation buttons and try with the TrackX,Y,Z y UpX,Y,Z group of buttons till the plane gets its position right. Blender things ;)

Do the same for crankshaft-1 adding a TrackTo constraint so it tracks to Empty2.

Constraints for crankshaft-1 :

Constraints for crankshaft-2 :

Fix any "weirdness" that might occur and we're done.

Now if you rotate the wheel around its axis you'll see how the crankshafts move by themselves as if they were joined in the real world.

Changing Empty0īs location close or far from the wheel's center will shorten or lengthen the run of crankshaft-2 when the wheel spins. Isn't it great ?

More Complex Models


You'll be tempted to start modelling your complex meshes right from the start before having checked if your mechanical system works. I personally don't think it's quite a good idea. It's better to set up properly your mechanism using simple objects as described here and then parent to it your fancy meshes.

To avoid the planes and cylinders to be rendered you only have to move them to a switched off layer. Don't worry if Blender shows funny things when you test-animate pressing ALT+A. It will be OK at rendering time. A small sample animation (DivX codec) can be seen here.

The nice thing about this approach is that you can easily modify or improve the functional part of the mechanism without messing around with million of vertices.

Well that's all for now, if you're lazy or have doubts take a look at this sample mechanism.