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. |
Try this:
Coin.rotateY = time * 100 * time; |
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. |
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. |
whoa .. nice logic ..
|
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." |
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......
|
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... |
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.
|
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* |
you could try multiplying by a negative number...
|
Hehe...this wasn't as easy as it first sounded but here's one solution:
Code:
if (time == 0) |
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? =)
|
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
|
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