Skip to main content
Inspiring
August 9, 2022
Answered

How to use a keyframe instead when you have an expression?

  • August 9, 2022
  • 3 replies
  • 1018 views

Greetings,

 

I have a property that is using a matth expression for the bulk of it's values, based on an input value from another layer, but I actually need to use some manual values that do not follow the expression calculation, so I was wondering how I could add keyframes with those manual values and have the expression, use the keyframe value instead, whenever there is a keyframe value present? Thanks for any help on this 🙂

This topic has been closed for replies.
Correct answer Dan Ebberts

It's combining different x,y movements to generate a composite camera panning movement, but since I have my Motion Blur turned ON for the foreground and background layers, the blur gets screwed up on the last frame of each panning section because the very next value starts in a completely different x,y location and AE just smears the blur on the last frame since I can't tell AE that I'm "restarting" my panning motion, so I need to make my last keyframe value just use the same x,y value on the second to last frame of each panning section along the timeline. 

 

var x= effect("PanZoom")("Anchor A")[0]-effect("xOffset")("Slider")+effect("shakeDelta")("Point")[0]*effect("x,y movement factor")("Slider")/100-effect("panDelta")("Point")[0]/2;
var y= effect("PanZoom")("Anchor A")[1]-effect("yOffset")("Slider")+effect("shakeDelta")("Point")[1]*effect("x,y movement factor")("Slider")/100-effect("panDelta")("Point")[1]/2;

[x, y]

 


I have no idea if this will affect your motion blur in the way you're hoping for, but on any frame where a keyframe exists, it should give the value of the keyframe, rather than the calculation:

x= effect("PanZoom")("Anchor A")[0]-effect("xOffset")("Slider")+effect("shakeDelta")("Point")[0]*effect("x,y movement factor")("Slider")/100-effect("panDelta")("Point")[0]/2;
y= effect("PanZoom")("Anchor A")[1]-effect("yOffset")("Slider")+effect("shakeDelta")("Point")[1]*effect("x,y movement factor")("Slider")/100-effect("panDelta")("Point")[1]/2;
val =[x, y]

if (numKeys > 0){
  f = timeToFrames(nearestKey(time).time);
  if (f == timeToFrames(time)) val = value; 
}
val

 

3 replies

Mylenium
Brainiac
August 9, 2022

Not a problem. Yopu simply use a slider that blends between your slider and your keyframed values as represented by the default "value" keyword. Since the slider itself then can be keyframed, it's easy enough to go back and forth using simple linear() functions or whatever you have in mind. All the same, you could of course fully offshore either the keyframe data or the expression to their own sliders and blend between those as well. Really depends on what you want to do.

 

Mylenium

persystAuthor
Inspiring
August 9, 2022

Hi Mylenium, this "linear" slider function sounds interesting to try. I have not used it before, do you have a reference for either how I might use it, or how to use it in general? Thanks for any additional info.

Dan Ebberts
Community Expert
August 9, 2022

What does the "math expression" look like?

OussK
Community Expert
August 9, 2022

As you want to change the expression value when it reaches a keyframe so I think you want to use (valueAtTime(t)) expression, so try to search for that and you will find a lot of example on how to use this expression 

Community Expert
August 9, 2022

You can call up a keyframe number and a keyframe value. You'll probably also need to add an if/else statement and maybe even an interpolation method to ease in and out of the keyframe value over time. 

 

You could also set up animations based on markers or layer in and out points, then add an if statement that looked for the nearest keyframe and turned off the expression if there were any keyframes in the property.

 

To be more specific, I would have to see exactly what you are trying to do.