Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Expression Editor Q about rotation increase (https://simplymaya.com/forum/showthread.php?t=1498)

Darkware 08-10-2002 09:50 PM

Expression Editor Q about rotation increase
 
1. create cylinder, name it "Coin"
2. scale so it's like a coin
3. Choose Window>Animation Editors>Expression Editor

Now, in this window, we can do all kinds of things to "Coin." I had planned on making it spin faster and faster as time went on, but I can't seem to get it right.

I thought that you could write something like the following, but it won't accept it. (this is roughly what the values would be)

if (time = 1) Coin.rotateY = time * 10;
if (time = 2) Coin.rotateY = time * 100;

and so on. I can get it to spin continuously with this expression -
Coin.rotateY = time * 100;
I just need it to increase over time.

kbrown 08-10-2002 10:15 PM

Try this:

Coin.rotateY = time * 100 * time;

Darkware 08-10-2002 10:53 PM

It works. I like Coin.rotateY = time * 50 * time; better, though. It has the right speed pick-up for what I'm doing. I'm going to sustain it's speed with this script: if (time > 20) Coin.rotateY = time * 1150; Otherwise, after 500 frames or so, it slows back down and begins to rotate the other way.

Does anyone know where to find some sample expressions? I'd like to look at some to get the feel for it since I'm just starting out. I want to figure out how to make things do something, adjust the speed for a given amount of time, and then slow it down. Stuff like that. I figure that if I can see a few simple samples here and there, I can grasp it.

*edit* one more thing, why does Coin.rotateY = time * 50 * time; work? I don't see the logic in the equation.

kbrown 09-10-2002 02:09 AM

Well, the value of the time variable increases constantly over time (boy, didn't that sound stupid :)) So if you write an expression like this:

Coin.rotateY = time;

The coin would be rotated 0 degrees at 0 seconds and 1 degree at 1s and so on...

But if you write it like this:

Coin.rotateY = time * 50;

The coin would be still rotated 0 degrees at 0 secs but 50 degrees at 2 secs, 100 deg @ 3s, 150 deg @ 4s...

And the final expression Coin.rotateY = time * 50 * time; would do this:

time = 0s -> 0 * 50 * 0 -> 0 degrees.
time = 1s -> 1 * 50 * 1 -> 50 degrees.
time = 2s -> 2 * 50 * 2 -> 200 degrees.
time = 3s -> 3 * 50 * 3 -> 450 degrees.

See, the speed increases over time.

adldesigner 09-10-2002 02:09 AM

whoa .. nice logic ..

kbrown 09-10-2002 02:15 AM

The function could be written like this too:

Coin.rotateY = pow(time, 2) * 50;

From MEL command reference:
"(pow) raises the first argument to the power of the second argument and returns the result."

Darkware 09-10-2002 02:49 AM

So why, after 500 or so frames, does the coin slow down and begin to spin the other way? Is it because the rotate Y value goes past 360 and increases until the value is so high that the digits exceed the alloted space provided? R-Y could go from 0-360, then back to 0 and so on, or it could go from 0-360-720-etc. See what I mean? Anyway......

kbrown 09-10-2002 03:50 AM

Yeah...didn't think of that. It might be an overflow issue. I'll get back when I have a solution.

*edit* It also might be because the acceleration increases so much that the coin rotates several rounds between two frames and looks like the direction is reversed...

mtmckinley 09-10-2002 04:35 AM

yeah, much like the optical illusion seen in car wheels and such. The mountain bike rider that I'm currently animating produces this effect... I thought I might have accidently reversed the rotation direction, but it's rotating correctly... just has the illusion of reversing direction.

Darkware 09-10-2002 08:58 PM

Yep, you're right. It was an illusion. I selected the coin as it spun around and the green outline of the edges flickered. Well, now that I have got it to slowly speed up and the hold it's rotation 20 seconds into the animation, I want to slow it back back down. Here's what I have so far:

Coin.rotateY = time * 50 * time;
if (time > 20) Coin.rotateY = time * 1150;

Now, I have worked with an expression several times, but cannot get it to work to slow it down. The expression would start out like this - if (time > 40) Coin.rotateY = ?

Basically, the coin is spinning around 1150 degrees per second. To make it gradually slow down, we must subtract a given amount from the equation. I thought of "reversing time * 50 * time thinking it would work, but I can't figure out a way. If it is possible to divide in expressions, that might work.
if (time > 40) Coin.rotateY =
time * 1150 (divided by) <an increasing number here>
If the last number is not an increasing number, it will not slow down. (I think) So, the only increasing number I know of to stick in here is "time." If there is a way to insert a number you want and have it increase however many numbers you prefere, that would work, too. *sigh*

mtmckinley 09-10-2002 09:02 PM

you could try multiplying by a negative number...

kbrown 09-10-2002 09:47 PM

Hehe...this wasn't as easy as it first sounded but here's one solution:

Code:

if (time == 0)
{
        //initialize
        Coin.rotateY = 0;
}
else if (time < 3)
{
        // accelerate to 3 secs of time
        Coin.rotateY = Coin.rotateY + time * 10;
}
else if (time < 6)
{
        // maintain constant speed while time is less than 6 secs
        Coin.rotateY = Coin.rotateY + 30;
}
else if (time >= 6 && time < 9)
{
        // decelerate back to zero speed between 6 and 9 secs
        Coin.rotateY = Coin.rotateY + 30 - 10 * (time - 6);
}

//this is just to prevent overflows
while (Coin.rotateY > 360)
        Coin.rotateY = Coin.rotateY - 360;

the deceleration equation might seem like a quick hack but it has a purpose if you think it over. I'll leave it to you to figure it out :) Feel free to ask, if you don't understand...

kbrown 09-10-2002 09:50 PM

Btw, a cleaner way for doing this would be to add few attributes to the Coin which would control when to accelerate and decelerate and so on...Anyway, wouldn't simple keyframes do the job? =)

Darkware 09-10-2002 10:18 PM

Wow. Quite impressive. I'm just trying to learn a little more about expressions, that's all. Keyframing probably would work. How on earth can you think this stuff up so quick? You just pull it out of thin air? Are you human? Oh no, I'm sorry. I didn't mean to insult you. I know you're made of nurbs. :p

kbrown 10-10-2002 07:01 AM

Hehe, the code is not actually that complex after you've read it with thought :)


All times are GMT. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018