Skip to main content
Inspiring
June 18, 2023
Question

About expressions. *Rotate layer by two layers position*

  • June 18, 2023
  • 2 replies
  • 877 views
Hi all...
 Maybe
who will help in writing the 
expression for the following situation. The composition layer has 2 position
keys. I want to add the following
behavior for the rotation property.
In the initial position key, the rotation
value is 0.0, in the final position key,
the rotation is also 0.0, but
in the interval between these position keys,
there is a deviation, by a certain amount,
for our example, let this value be 90.0 degrees.
And I would also like to control the position of the
peak relative to the position keys, and the tangents
of the approach and to this value of 90.0

 

This topic has been closed for replies.

2 replies

Community Expert
June 18, 2023

If you want to use the position of a keyframe in the timeline to control the rotation of a layer, use two ease or linear interpolation method and the time between the keyframes and then set the ratio between the two times and the maximum angle. 

 

Let's say that if the time between keyframes is greater than 1 second, the layer does not rotate, but if the time is less than one second, the layer would rotate 180º and back again. That expression would look like this:

 

t = time;
minTime = 1;
tStart = position.key(1).time;
tEnd = position.key(2).time;
tMiddle = tEnd - tStart / 2;
restAngle = 0;
maxAngle = 180;
if (tMiddle - tStart < tEnd - tStart/2){
	rStart = ease(t, tStart, tMiddle, restAngle, maxAngle);
}
if (tMiddle - tEnd < tEnd - tStart/2){
	rEnd = ease(t, tMiddle, tEnd, maxAngle, restAngle);
}
if (tEnd - tStart < minTime){
	r = rStart + rEnd - 180;
}

else{
	r = 0;
}

 

If you wanted the time between keyframes to generate a minimum and maximum angle. you just need to do the math. 

 

To create an expression that does exactly what you want it to do would require you to give us the exact parameters. For example, if the time between keyframes is one second, then the layer rotates from 0º to 90º, but if the time between keyframes is two seconds, the layer rotates between 0º and 180º.

 

Maybe that explanation will give you something to build on. 

AnyONAuthor
Inspiring
June 18, 2023

Thank you for your attention to my question Rick, I sketched something similar in the example you gave, but I did not know that in the if else condition, you can use an expression like

rStart = ease(t, tStart, tMiddle, restAngle, maxAngle);

In that case it's possible...

 

Community Expert
June 18, 2023

I think I made a mistake calculating time in that example, so the move is not centered. There is probably another error there too.

 

If I get a chance later, I'll try and fix it by opening up AE and fiddling with the math.

 

EDIT:I fixed the expression to center the move. It now looks like this:

t = time;
minTime = 4;
tStart = position.key(1).time;
tEnd = position.key(2).time;
tMiddle = (tEnd - tStart) / 2;
restAngle = 0;
maxAngle = 180;
if (tMiddle - tStart < tEnd - tStart){
	rStart = ease(t, tStart, tStart + tMiddle, restAngle, maxAngle);
}
if (tMiddle - tEnd < tEnd - tStart){
	rEnd = ease(t, tMiddle, tEnd, maxAngle, restAngle);
}
if (tEnd - tStart < minTime){
	r = (rStart + rEnd);
}

else{
	r = 0;
}
r - 180;

That expression should give you a clockwise rotation from zero to 180º and back to zero any time the position keyframes are less than four seconds apart. 

ShiveringCactus
Community Expert
Community Expert
June 18, 2023

Sounds like you're describing wanting to keyframe a wiggle, so that you can control when it's in use.

I made a tutorial a few years back to explain how:

https://youtu.be/SqVZcGEZVp4