SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Expression Editor Q about rotation increase

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
08-10-2002, 09:50 PM   #1
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
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.
__________________
www.Darkware3D.com
  Reply with quote
08-10-2002, 10:15 PM   #2
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Try this:

Coin.rotateY = time * 100 * time;
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
  Reply with quote
08-10-2002, 10:53 PM   #3
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
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.
__________________
www.Darkware3D.com

Last edited by Darkware; 08-10-2002 at 10:55 PM.
  Reply with quote
09-10-2002, 02:09 AM   #4
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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.
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
  Reply with quote
09-10-2002, 02:09 AM   #5
adldesigner
Registered User
 
adldesigner's Avatar
 
Join Date: Sep 2002
Location: CCS, Venezuela
Posts: 3,363
whoa .. nice logic ..
__________________
adldesigner
Caracas, Venezuela
Hell .. not gone perse, but with a certainly lower post count per day.

  Reply with quote
09-10-2002, 02:15 AM   #6
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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."
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
  Reply with quote
09-10-2002, 02:49 AM   #7
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
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......
__________________
www.Darkware3D.com
  Reply with quote
09-10-2002, 03:50 AM   #8
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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...
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!

Last edited by kbrown; 09-10-2002 at 03:53 AM.
  Reply with quote
09-10-2002, 04:35 AM   #9
mtmckinley
The Maya Mountain
 
mtmckinley's Avatar
 
Join Date: Aug 2002
Location: Seattle, WA
Posts: 8,245
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.
__________________
-Mike
www.mtmckinley.net
The Maya Toolbelt
  Reply with quote
09-10-2002, 08:58 PM   #10
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
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*
__________________
www.Darkware3D.com
  Reply with quote
09-10-2002, 09:02 PM   #11
mtmckinley
The Maya Mountain
 
mtmckinley's Avatar
 
Join Date: Aug 2002
Location: Seattle, WA
Posts: 8,245
you could try multiplying by a negative number...
__________________
-Mike
www.mtmckinley.net
The Maya Toolbelt
  Reply with quote
09-10-2002, 09:47 PM   #12
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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...
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!

Last edited by kbrown; 09-10-2002 at 09:59 PM.
  Reply with quote
09-10-2002, 09:50 PM   #13
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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? =)
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
  Reply with quote
09-10-2002, 10:18 PM   #14
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
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
__________________
www.Darkware3D.com
  Reply with quote
10-10-2002, 07:01 AM   #15
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Hehe, the code is not actually that complex after you've read it with thought
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Expression please help! takecake Programming 1 11-02-2017 03:20 PM
Rotation Matrix from transform, rotation, and pivot devthep Programming 1 01-03-2012 04:07 PM
rotation expression troubles bendingiscool Programming 1 26-10-2007 10:18 PM
expression question bingo Maya Basics & Newbie Lounge 1 17-05-2004 04:51 PM
Expression for decellerating rotation animation PappaSmurf Animation 1 26-05-2003 05:05 AM