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

Advanced expression (position) question

Explorer ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

I'm usually pretty good with expressions, but I'm really stumped on this one:

For the sake of keeping it simple, let's say I have:

1. A layer

2. A null object with a slider

I want my layer to slide in (x position only) from Point A, to Point B, pause on Point B for a few seconds, then slide back to Point A.

Here's the challenge: I want Point B to be controlled by the slider, but I always want Point A to be the same exact starting/ending point. (say 0, for the sake of simplicity). So the animation should go:

0 to X, then X back to 0, where X is the value driven by the slider.

Hope this makes sense. Thank you in advance to anyone who might be able to help.

TOPICS
Expressions

Views

4.6K

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

Advocate , May 12, 2017 May 12, 2017

You need slight modification (the thing called C replaces A at the very end):

t0 = inPoint;

transitionDur = 3;

holdDur = 5;

// A, B : start/end value for the x coordinate

A = valueAtTime(0)[0];    // or some constant numeric value like 0

B = thisComp.layer("Null 1").effect("Slider Control")(1).value;

C = 50;

y = value[1];                // or some constant numeric value like 0

t1 = t0+transitionDur;

t2 = t1+holdDur;

t3 = t2+transitionDur;

x = (time<=t1) ? linear(time, t0, t1, A, B) : linear(time, t

...

Votes

Translate

Translate
Engaged ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

keyframe your A and B position and try this on your position value

s = LINK ME TO YOUR SLIDER CONTROL EFFECT;

valueAtTime(linear(s,0,numKeys,key(1).time,key(numKeys).time))

The slider will now blend between the 2 positions

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 ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

Thank you for your help.

Unfortunately, this didn't quite work. Now my layer x position stays at 0 throughout, no matter what the slider value. Any other ideas?

Thanks again.

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
Advocate ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

This might be it:

t0 = inPoint;

transitionDur = 3;

holdDur = 5;

// A, B : start/end value for the x coordinate

A = valueAtTime(0)[0];    // or some constant numeric value like 0

B = thisComp.layer("Null 1").effect("Slider Control")(1).value;

y = value[1];                // or some constant numeric value like 0

t1 = t0+transitionDur;

t2 = t1+holdDur;

t3 = t2+transitionDur;

x = (time<=t1) ? linear(time, t0, t1, A, B) : linear(time, t2, t3, B, A);

[x,y];

Xavier

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
Engaged ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

how do you get that nice text formatting for your code?

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 ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

Thank you! This is exactly what I needed.

Now, for an added challenge: the scope of the project changed a little, so instead of having the layer move back to its original position (0), now, after pausing on the slider value, it needs to move to a third position, say 50 for example.

So the animation should go:

0 to X, pause, then X to 50. (50 always being constant)

I have admit, I am mostly unfamiliar with what you came up with in your expression. Thanks again for your help!

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
Advocate ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

You need slight modification (the thing called C replaces A at the very end):

t0 = inPoint;

transitionDur = 3;

holdDur = 5;

// A, B : start/end value for the x coordinate

A = valueAtTime(0)[0];    // or some constant numeric value like 0

B = thisComp.layer("Null 1").effect("Slider Control")(1).value;

C = 50;

y = value[1];                // or some constant numeric value like 0

t1 = t0+transitionDur;

t2 = t1+holdDur;

t3 = t2+transitionDur;

x = (time<=t1) ? linear(time, t0, t1, A, B) : linear(time, t2, t3, B, C);

[x,y];

@foughtthelaw : You need to enable the "Advanced Editor", then >>(insert)>(SyntaxHighlightning)>javascript

Xavier

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 ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

Thank you very much for all your help! That's exactly what I needed and works perfectly!

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
New Here ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Hi, I have a basic rectangular shape with text sliding from left to middle of the screen (x1  to x2), and when it reach it give a shake (Wiggle effect). I have key framed the wiggle effect to do that. I have created null and created controls for color and other parameters. But I don't know how to create a control for the wiggle effect only for the particular period I keyframed for. Played all day .. No luck. Please help me to solve this.

See the file here . https://drive.google.com/open?id=1g1hsfh9clb3ssXCEpIIZ7ci2b5iyjLwS

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 ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

LATEST

I just answered this same kind of question in another thread. You can use the inPoint and outPoint of another layer in an if-else statement to turn something on or off. Check out this example:

 

ctrl = thisComp.layer("Null 1");
amp = effect("Slider Control")("Slider");
if (time < ctrl.inPoint)
	wiggle(6, amp)
else if (time > ctrl.outPoint)
	wiggle (10, amp)
else value

 

This expression is defining ctrl as a layer named "Null 1" in the first line. It is looking for a slider control on the same layer and calling that variable a. The if statement says if the time is less than the in point of ctrl (Null 1) then wiggle 6 times a second whatever the value in the slider is but if the time is greater than the out point of Null 1, wiggle 10 times a second whatever the value of the slider is, but in between the in and out point of the ctrl layer (else) just use the value of this property even if it has keyframes. It's pretty straight forward. 

 

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