Spinning Bones, Meshes and Empties

Some kind soul or was that sole, asked me to add a version of one of my posts to the tutorials/tips section, so here it is:

The question related to making bones spin at or beyond 360 degrees and the problems associated with them “snapping back” the wrong way to get back to 0 degrees rotation, which they do with monotonous regularity, Shouting at them doesn’t work so I looked at a different, more reliable solution.

Here’s a picture, I like pictures:

The Solution:

That should read “The Solution - or one of them”

Key framing rotations of bones over 360 degrees does not work reliably! Please feel free to prove me wrong, if you know better. This is particularly true if you key frame say 90 degree increments, then copy your first frame to be the last one - the little blighter will snap back the wrong way. I gave up on this approach after struggling to make four radiator fans spin using an armature, sometimes you can type values in the transform box and keyframe these, but you must increase the value all the time, so the sequence might be 100, 200, 300, 400, 500, etc. making sure you never use multiples of 360, but still the little varmint will snap back occasionally, so it’s not a reliable method.

Drivers are the answer, see the above figure, just insert a single driver on the rotational axis transform box, To do this RMB click the box and select “Insert Single Driver”. Then go to the Graph Editor, select Driver Mode to see your driver setup, you may have to press N to see the expressions menu, Then do one of the following:

  1. To make a bone rotate all the time, use a Scripted Expression of say (frame * pi) / 10 this will cause the bone to rotate a complete revolution every 20 frames, if this is too fast, use a bigger number.

  2. To do the same but have the bone at rest in frame 1 the expression would be ((frame - 1) * pi ) / 10. In the example above the bone would be rotated by pi / 10 radians on frame 1. Come on, the maths is not that hard!

  3. To control the speed and direction of rotation, add an Empty at Z = 0, X and Y anywhere you want. Then add a variable to your expression, this being the Empty as the target - Transform Channel - Z location.

Your expression will then be ((frame - 1) * pi * var) / 10

The bone will now not move if the Empty is at Z = 0, at Z = 1; it will rotate the same speed as before, at Z = 2; twice as fast, at Z = 0.5; half as fast, etc. At Z = -1; it will rotate the same speed but backwards, and so on. You can of course key frame the position of the empty in your animation.

  1. To make a bone rotate say 2.5 revolutions one way then rotate back 1 revolution, etc. Use the empty as before placed at Z = 0. The variable is the same as above and the scripted expression is (var * pi * 2) When you move the empty to Z = 2.5, the bone will rotate 2.5 turns, When you move it then to Z = 1.5, the bone will rotate back one turn. When you move the Empty back to Z = 0, the bone will rotate 1.5 revolutions back to where it started. You can of course key frame the Empty’s position in your animation.

If your bone is going the wrong way (ooh err missus!) with the expression, simply insert a minus sign immediately in front of one of the bits, e.g. -pi making sure you don’t have a gap. This is a foolproof method, I think and the bones will always behave themselves.

You will note that you do not need to remember the value for pi (3.1418 will normally do) because you can use “pi” in the expression and Blender kindly works it out for you. You can also use “math.pi” as an expression in Python scripts.

Don’t forget you must have “Auto Run Python Scripts” checkbox set in User Prefs > File tab, to run scripted expressions and also scripted expression turns are in Radians not degrees, there are 2 * pi radians in a full circle. This means that if you rotate an object by a value of 1 in a scripted expression, it will turn 57.29199821758228 degrees (approximately). To rotate an object a precise number of degrees, the expression will be of the form (N / 360) * 2 * pi, where N is the required number of degrees, this of course can be simplified, if required, so 90 degrees is pi / 2.

Here’s the blend file:

rotating-bones-empties.blend (467 KB)

Just press Play (ALT-A) and move the sliders in the Z axis.

Hope this proves useful and reduces the bad language resultant from bones not behaving, Cheers. Clock.


See the update below…

Definitely worth the read for anyone interested in driver expressions.

UPDATE to the Tutorial.

There are some more issues relating to wheels moving along a track or along an axis, and then rotating as they should.

I have prepared a blend file with several examples in it, attached below:

wheel-issues.blend (872 KB)

Just press Play to see it all working, then you can take the blend file to pieces to examine how the drivers all work.

Don’t forget to check “Auto-run Python Scripts” in User Prefs > File tab, or the drivers won’t work. :no:

Cheers, Clock.

Just spotted this. Good stuff. I’ll check it out in detail and see how confused I can get.

This is weird though:

…and also scripted expression turns are in Radians not degrees…
So transforms in the usual GUI default to degrees, but they’ve gone and made scripts default to radians? Brilliant. Awesome consistency FTW. :rolleyes:

Not that it’s a serious problem if you’re aware of it, but it does seem to be a case of the left hand devs not knowing what the right hand devs are doing.

@Gumboots - I could not possibly comment…

I prefer radians for these types of drivers since if you move a 1 unit radius object forward 1 unit you have to rotate it 1 radian - so it makes the maths easier for those not good at difficult sums, i.e. the relationship between radius, movement and rotation is consistent and dependent purely upon radius. Here endeth the maths lesson.

Some of the objects in the blend file in post 4 use curves as tracks or track vectors, some do not if they are moving along a global axis. I would be interested if anyone can get rid of the track vectors for straight line movements OFF the global axes without writing complex Python scripts. If you know how to do this - please add the knowledge as a post here.

Cheers, Clock.

In response to a thread in Animation and Rigging, I have added two more options, one which just has a wheel rotating around a fixed point at a fixed radius and does not use a curve path, and the second, which moves around an oval and again does not use a curve path. I have to say that I prefer the curve path option, but these two additions show how it can be done without.

It is worth noting, when you are putting values into location boxes of objects, or values in any number boxes that you can enter something like (pi * 2) + 10 instead of having to use your calculator to work out what the expression might be.

Cheers, Clock.

Here’s the revised Blend file: wheel-issues.blend (984 KB)

As ever, just press play to see them working, you can then take the blend file to pieces to see how they work. :smiley:

if anyone would like any more options, just let me know and I’ll do my best.