ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Change Y position based on Null's rotation value

FAQ   •   VIEW ALL
 Change Y position based on Null's rotation value by Ian Blomon 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]```

 Re: Change Y position based on Null's rotation valueon 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)

 Re: Change Y position based on Null's rotation valueon 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".
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