Home Youtube GitHub

Controlling the speed of rotation using a attribute


#1

Hi,

In my production I was asked to make a object rotate like a fan with the help of a switch. So I created a attribute with values 0 to 3 (float) and multiplied the rotations according to the requirement.

This is how the requirement was.

slow speed = 1/200 (round/frames)
medium speed = 1/150 (round/frames)
fast speed = 1/100 (round/frames)

so when the attribute is at 0 it doesn’t rotate, when it is at 1 its at slow speed and so on.

The process I did this was I created a set driven key with the attribute and a multiply divide (input2Y) node with values
0 - 0
1 - 1
2 - 1.5
3 - 2

Now I keyed the input1Y of the node at 0 and 300 frame with transition from 0 to 360 degrees with a linear curve. The I connected the OutputY to the object which I need to be rotated.

The problem with this setup is it rotates fine when the values in the attributes are 0,1,2 or 3. But if it is a transition from one speed to another they don’t work properly. I haven’t been able to figure out a solution for this problem.

Here is the maya file to check what exactly I’m trying to talk about.
https://drive.google.com/file/d/1yIuidxy1HJ85bQw77PKbVu0GLAYYh1Ck/view?usp=sharing

Sorry, this is not a mGear related issue. Could anyone help me with this.

Thanks


#2

Hello there

I don’t know if I understand if you are talking about the problem. Below is my plan.

You can use an expression control to rotate the y-axis

Create an expression as:

pPyramid1.rotateY = frame*gear_ctl.onoff 10gear_ctl.gear

The parameter of gear_ctl.onoff is set to integer 0-1

The parameter of gear_ctl.gear is set to float 0-3

The larger the value of gear_ctl.gear, the faster the speed. The smaller the value, the slower the rotation speed.

Hopefully it helped you

Cheers


#3

First, pet peeve time: it is a “Driven Key”. You set a Driven Key. Animators don’t “set set keys”. And riggers don’t “set set driven keys”. :slight_smile:

The problem is that you are just multiplying, so once you are at a non-zero value, it is scaling from the value it is currently set at.

I can’t read fury_Night’s response very well, but it looks like a simple multiplication expression, and will have the same problem.

The only way that you can make an automatic rotation that can change it’s speed over time, is to use a way of querying what the current rotation is, and then adding more rotation each frame, multiplied by the speed.

It is possible to do this with an expression. I don’t know if this is the best way. You can also query values in a Python node in Mash. There are some interesting possibilities there.

I make a Cylinder with a float attribute “speed”. This will query the current value of the cylinder, and then each frame, add the speed. In order to reset the rotation, you could add an if statement on frame 0 or 1, to reset the value to 0. Or add a “reset” boolean attribute or something.

$currentValue = `getAttr pCylinder1.rz`;

$speed = pCylinder1.speed;

pCylinder1.rotateZ = $currentValue + $speed;

#4

Hey @chrislesage

Sorry for not replying earlier. I was figuring how to make this work even after you explained it to me. I was a fool for not understanding your logic properly. But it works.

Thank you