• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Link slider with 1 keyframe to adjust the Y value while maintaining X value

Community Beginner ,
Sep 11, 2018 Sep 11, 2018

Copy link to clipboard

Copied

Dear Creative Guru's,

I am looking for an expression that would let me scale the y axis of only the last of 2 keyframes using a slider while maintaining a fixed X value. So for example:

Keyframe 1: [300,0]   Keyframe 2: [300,whatever the slider value is]

I can't seem to figure it out. So any help would be much appreciated.

Kind regards,

Robin

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Sep 12, 2018 Sep 12, 2018

This works but don't forget to apply a Slider Expression Control to the same layer and name it Y Scale Offset (last KF).

------------------------------------

scalarVal = effect("Y Scale Offset (last KF)")("Slider");

targetProp = transform.scale;

lastKey = targetProp.numKeys;

lastKeyTime = targetProp.key(lastKey).time;

linear(time,key(1).time,lastKeyTime,[value[0],value[1]],[value[0],value[1]+scalarVal])

------------------------------------

Votes

Translate

Translate
Community Expert ,
Sep 11, 2018 Sep 11, 2018

Copy link to clipboard

Copied

Scale values are in an array like this: [50, 100]

That translates to x at 50% and y at 100%.

You can pull the existing value from a keyframe using the value method. This is how you would tell an expression to look at the existing value for x and give the Y value 75%.  [value[0], 75];

A slider only has one set of values. You can extract the value of a slider easily by just using the pickwhip to attach a variable to the slider by simply typing y = and then dragging the pickwhip to the expression slider and closing the line of code with a ;  If the slider is attached to the same layer you get something like this:
y = effect("Slider Control")("Slider");

You can also so simple math using  +, -, *, and /

If you want the slider to modify the existing y keyframes then you would write your expression like this:

y = effect("Slider Control")("Slider");

[value[0], value[1] + y]

If you wanted to control the Y value directly with the slider and ignore any existing values for y the expression would be simply:

y = effect("Slider Control")("Slider");

[value[0], y]

That should get you started. The Search Help field in the top right corner of AE will point you in the right direction if you simply type expression slider and press enter. It's pretty easy to figure out basic expression language.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 11, 2018 Sep 11, 2018

Copy link to clipboard

Copied

Rick,

Thank you for your detailed explanation about the subject. This will get me very close to my end goal. However is there any way to make the expression below only effect the last keyframe out of 2 keyframes.

y = effect("Slider Control")("Slider");

[value[0], y]

this is roughly what I am looking for: Keyframe 1: [300, always 0]   Keyframe 2: [300,whatever the slider value is]

looking forward to your reply,

Robin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

This works but don't forget to apply a Slider Expression Control to the same layer and name it Y Scale Offset (last KF).

------------------------------------

scalarVal = effect("Y Scale Offset (last KF)")("Slider");

targetProp = transform.scale;

lastKey = targetProp.numKeys;

lastKeyTime = targetProp.key(lastKey).time;

linear(time,key(1).time,lastKeyTime,[value[0],value[1]],[value[0],value[1]+scalarVal])

------------------------------------

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

Roland gave you a solution. That is an awful lot of work to do when you could just set a couple of keyframes for the slider. I also think that Roland has come up with a recursive expression that will slow down rendering the longer it is between keyframes.

Because you want to start with a Y scale of zero I would probably just write an expression that looks at the layer in-point and uses time as a multiplier for the Y scale. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

I don't see a recursive nature in the script. On the very first frame, all the variables are known; including the last line.

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

Roland, I just gave it a quick look. You are probably right. It's pretty easy to get into a recursive situation when you start referring to time. It's still an awful lot of work to go to just drive a simple scale animation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

LATEST

Hello from the future! Just popping in to say this expression really helped me out for a project. I needed control over both the X and Y so I just made a new slider, made it a variable in the expression, and added it to the second "value[0]" because that made enough intuitive sense and it happened to work out. Thing is, I don't really understand what's happening in the final line of the expression, or why I couldn't make it work using one point controller instead of two X and Y sliders. Anywhere you'd recommend going to learn more about how to understand and write AE expressions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines