ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Use A Null Slider To Interpolate Between Series Of Positions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ludwig Sweet
Use A Null Slider To Interpolate Between Series Of Positions
on May 8, 2019 at 1:22:11 am

I have a layer that I'd like to smoothly move between a series of pre-set x,y positions (2, 54)(-4, -174)(0, -12)(8, 190) etc. Obviously I can keyframe each position manually, but I'd like to be able to use a parent "master slider" to interpolate between each x,y value.

For example:

I'd like to be able to enter a value of "1" into the "master slider", and have the child layer's position move to 2, 54; then enter a value of "2" into the "master slider" and have the child layer move to position (-4, -174); then enter a value of "3" into the "master slider" and have the child layer move to position (0, -12); then enter a value of "1" (again) into the "master slider" and have the child layer move back to position (2, 54)..etc...

In this example I use 3 different x,y positions for the sake of simplicity, but ultimately I'd like to be able to smoothly move between 100+ different positions using this method.

Also, it's important that whatever script I ultimately use isn't temporal-based/timeline-based, but is based purely on x,y positions. I'm new to scripting, but I'm hoping there's an elegant solution.


Return to posts index

Christian Geijer
Re: Use A Null Slider To Interpolate Between Series Of Positions
on May 8, 2019 at 9:38:39 am

This maybe isn't exactly what you want but it might help you on your way.

One way could be to create a .json-file with all the different positions mapped to the corresponding slider value like this:
{
"positions": {
"1": {
"x": 2,
"y": 54
},
"2": {
"x": -4,
"y": -174
}
}
}


Place the .json-file (here named data.json) in your composition and then, with the value from Master slider (in my example placed on a null layer named "Control"), change the position of the object you want to move around with an expression that looks something like this:
id = thisComp.layer("Control").effect("Master slider")("Slider").toString;
x = thisComp.layer("data.json").source.sourceData.positions[id].x;
y = thisComp.layer("data.json").source.sourceData.positions[id].y;
[x,y]


This, however, only works with the slider being set to whole numbers that you also have defined in data.json and does not work if the slider animates between the different values. You maybe can define the first and second positions and use linear() to animate between them, but I'm not sure how you'd want that to work in your specific case.


Return to posts index

Kalleheikki Kannisto
Re: Use A Null Slider To Interpolate Between Series Of Positions
on May 8, 2019 at 2:01:40 pm

Basically the same matter as discussed here. No ready expressions, but the basic methodology is there.

https://forums.creativecow.net/thread/227/41791

If the transition time is always the same -- which it would have to be if you use just a single slider -- you can simplify this by looping back from the current frame for the number frames that cover the transition and checking if the hold keyframe value has changed during that time. If it has, you can calculate the progress between the two positions (read from an array) from how many frames back the value changed (in relation to the full transition time).

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Kalleheikki Kannisto
Re: Use A Null Slider To Interpolate Between Series Of Positions
on May 8, 2019 at 2:37:30 pm

For the simpler implementation with fixed transition time and one slider (using hold keyframes), slider on layer "controls".

Position expression:

pos_array = [[2, 54],[-4, -174],[0, -12],[8, 190]]; // predefined positions array
tt = 10; //transition time in frames
cv = thisComp.layer("controls").effect("Slider Control")("Slider").value; //current slider value
tp = 0; // transition progress default
for (i=0; i<tt; i++) {
pv = thisComp.layer("controls").effect("Slider Control")("Slider").valueAtTime(time-i*thisComp.frameDuration);
if(pv!=cv){
tp = i/tt; // transition progress, from 0 to 1
break;
}
}
if(tp==0){newpos=pos_array[cv-1];// if not in transition, return the current index position
}else{
newpos = pos_array[pv-1]*(1-tp)+pos_array[cv-1]*tp;
}
newpos


Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]