2

My question is pretty simple.

How to make an object copy rotation of another object with same speed but only every second circle. I know I can animate that using keyframes, but I need to have in constraint.

Michal
  • 53
  • 7

1 Answers1

8

You could add a scripted driver to the desired rotation axis of the object with the intermittent rotation, using the following expresion:

var*(int((var/(2.0*pi))%2))

where the variable var, (or whatever you want to call it) refers to the relevant rotation (X,Y,or Z) of the driving object.

enter image description here

Here, the Z rotation of the triangle is being driven by the expression, in which var refers to the the Z rotation of the square.

EDIT in response to your comment:

We can make the expression a little more general by implicitly casting True and False to 1 and 0:

var*(int((var/(2.0*pi))%3)==1)

In this version, the number where the 3 is determines the number of turns in the cycle, and the number where the 1 is says which of the turns to follow, with 0 as the last, counting back. So this example would make the driven object follow the driver on the second of every three turns.

So, in order to have alternating rotations, in the example below, the green triangle uses:

var*(int((var/(2.0*pi))%2)==1)

..and the yellow triangle uses:

var*(int((var/(2.0*pi))%2)==0)

enter image description here

Any more than this - say, "the second and fifth out of every seven".. and it would probably be tidier to write a little function, and add it to the driver_namespace.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • That's what I was looking for. Thank you very much! – Michal Sep 29 '18 at 15:02
  • I also tried making third object that rotates when the second object doesn't I tried this var(int((var/(4.0pi))%2)) Bu it hasn't worked out. – Michal Sep 29 '18 at 15:28
  • 1
    @Michal.. I've made an edit to cover this.. – Robin Betts Sep 29 '18 at 17:53
  • 1
    Consider div instead of mod in this case. var * (var // twopi)Mod is handy for mapping [eg mapping on 0, 1 for offset on an orbit](https://blender.stackexchange.com/a/118300/15543) div//` wil give you the whole number that you are calculating with int-divide-modulus combo – batFINGER Sep 29 '18 at 20:13
  • Thanks, @batFINGER, I'm stumped. I can see how to get rid of the int, (e.g. var* (((var//(2.0*pi)%5))in[1,2])) but I can't figure out how to have an infinite cyclic function without a % somewhere. Please go ahead and fix the answer, if you like. – Robin Betts Sep 30 '18 at 00:53
  • 1
    Sorry re confusion, was pointing out that revs or laps can be calculated using div not that mod and int were always avoidable. The ternary operator is another (often more) readable way eg var if 1.0 <= (var // twopi) % 5 <= 2.0 else 0 Ternary op can be nested. – batFINGER Sep 30 '18 at 03:06
  • 1
    As pointed out often its easier to make a method in the driver namespace to avoid the single line madness. Akin to print pages '[1, 3, 4-6]` Would like to see a subexpression in drivers akin to math surface to cut down long expressions.. . Mapping equation to 0 or 1 and driving a copy rotation constraint influence is another way that can be less complex equation wise. Is the square above slightly leading the triangle? 8UV's too man.. envious lol. – batFINGER Sep 30 '18 at 03:06
  • @batFINGER I agree. The little expression window has the effect of turning everything into code golf. I was once a bit of a Perl camel, but I'm way off even apprentice Pythonista, so your crit is always more than welcome. I don't think the square is leading.. the skew dotted line is to the manual rotation cursor, out of shot. I seem to have kicked off at about -93. Envious? I don't get the impression your rep. needs a voting system. – Robin Betts Sep 30 '18 at 09:34
  • @RobinBetts Thank you very much! I tried it and both objects skip every third circle, so object A rotates all the time then object B does 360 and stops then object C stops and does 360. After this I want the B to come again, but they both stop for one circle. – Michal Oct 01 '18 at 21:01
  • @Michal.. see extension to edit.. hope I've got what you mean, this time :) – Robin Betts Oct 02 '18 at 05:46
  • Yes, it works perfectly! Thank you! But, could you also add offset to this? – Michal Oct 02 '18 at 19:49
  • @Michal Just bracket the whole expression up and add the offset at the end.. (or the beginning)... e.g. (expression)+(pi/2) would shift the rotation of the driven object by 90 degrees anticlockwise..(all angles are expressed in radians to try and keep everything short) :D.. – Robin Betts Oct 02 '18 at 23:10