ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change Y position based on Null's rotation value

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ian Blom
Change Y position based on Null's rotation value
on May 14, 2018 at 8:19:00 am

Hi

I'm trying to move a 3D object on its Y-axis as the value of a null object's rotation changes. This is for a character rig that I'm busy with, so basically, as the null object is rotated on its X-axis (up/down), the object must have a slight offset and have a smooth movement. In this case the character's eye. The null object rotates the body to tilt up and down and therefore the eye should follow realistically.

I have the following code which works, but the eye jumps from the one position to the next as the null reaches a certain value or goes above or below 0:

Expression code on the object's rotation:

x = value[0];
y = 100;
z = value[2];

if(thisComp.layer("Face Rotation X").transform.xRotation > 35 ) [x,y,z] else [x,-y,z]
if(thisComp.layer("Face Rotation X").transform.xRotation == 0 ) [x,0,z]


I need the object to have a smooth position change and not jump as the null goes above or below 0.

Will appreciate any help in this regard.

Thanks

x = value[0];
y = 100;
z = value[2];

if(thisComp.layer("Face Rotation X").transform.xRotation > 35 ) [x,y,z] else [x,-y,z]
if(thisComp.layer("Face Rotation X").transform.xRotation == 0 ) [x,0,z]


Return to posts index

Steve Bentley
Re: Change Y position based on Null's rotation value
on May 14, 2018 at 4:54:05 pm

Based on your code, when the value falls below 35 the y position will instantly pop from 100 to -100, similarly when the value hits 0 the value will instantly pop from -100 to 0. Is that the intention? And when you go below 0 the value will pop to -100 again.

Or do you need something like a range mapper? Where you have a set of values (say 0-35) and you want to linearly map another set of values to that (say -100 to 100).
If you call the set of values 0-35 values set1 and call 100 to 100 value set2 here's the equation for that. Assuming you have a value from set1 (valueFromSet1) that you want to map to the values in set2.

newSet2value = lowSet2 + (valueFromSet1 - lowSet1) * (highSet2 - lowSet2) / (highSet1 - lowSet1)



Return to posts index

Steve Bentley
Re: Change Y position based on Null's rotation value
on May 15, 2018 at 9:05:07 pm

My answer falls under the topic of "when you have a hammer everything looks like a nail".
I had been doing range mappers in another software package when I answered your post and totally forgot about the range expression.
Here's an answer from Jay Roth that I took from a post a few hours after yours. (saves me typing)

I think you'll want the linear expression hooked up to a expression slider on a null.

The linear expression works by taking one set of values doing the math to interpolate them to another set of values. So, you would want to put this expression on the range selector of each of your text layers

range = thisComp.layer("YOUR NULL").effect("Slider Control")("Slider");
linear(range, 0, 10, 0, 100); // Change the first two numbers to be the keyframed values you want for the slider for each layer

Essentially what this is telling the range selector is "As the null slider goes from 0 to 10, change the range selector value from 0 to 100.




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]