Forums › Adobe After Effects Expressions › Use markers to control camera position?
-
Use markers to control camera position?
-
Scott Green
January 19, 2022 at 6:00 amHi Dan. I’ve been playing with this expression some more to make a position change based on the markers and have ran into an issue that I just can’t seem to figure out, can you help?
I’ve attached a screenshot and also the project file.
What happens is, the position is skipping Pos2 and going directly to Pos3, then at the Pos3 marker it errors. Can you see why that might be?
Also, is there a way to make the position start at the first ‘Start’ marker rather than in the top left corner?
Pos0 = thisComp.layer("Start").transform.position;
Pos1 = thisComp.layer("Position 1").transform.position;
Pos2 = thisComp.layer("Position 2").transform.position;
Pos2 = thisComp.layer("Position 3").transform.position;
moveTime = effect("moveTime")("Slider");
m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if (n > 0){
t1 = m.key(n).time;
t2 = t1 + moveTime;
if (m.key(n).comment == "Start"){
ease(time,t1,t2,valueAtTime(t1),Pos0);
}else if(m.key(n).comment == "Pos1"){
ease(time,t1,t2,Pos0,Pos1);
}else if(m.key(n).comment == "Pos2"){
ease(time,t1,t2,Pos1,Pos2);
}else if(m.key(n).comment == "Pos3"){
ease(time,t1,t2,Pos2,Pos3);
}else{
value;
}
}else{
value;
}
-
Scott Green
January 19, 2022 at 6:05 amSorry Dan, I’ve just spotted the issue, I had Pos2 written in line 4 instead of Pos3, apologies.
Still, if there’s a way to make the pointer start at the “Start” position rather than the top left corner that would be really helpful.
Thank you.
-
Scott Green
January 19, 2022 at 6:32 amOne more thing, which of these values controls how it eases into position?
Is there a way to control the amount of ease so it can be smoother when it moves into position?
-
Dan Ebberts
January 19, 2022 at 3:11 pm<div>A couple of small changes should keep it at “Start” initially:</div>
Pos0 = thisComp.layer("Start").transform.position;
Pos1 = thisComp.layer("Position 1").transform.position;
Pos2 = thisComp.layer("Position 2").transform.position;
Pos3 = thisComp.layer("Position 3").transform.position;
moveTime = effect("moveTime")("Slider");
m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if (n > 0){
t1 = m.key(n).time;
t2 = t1 + moveTime;
if (m.key(n).comment == "Start"){
Pos0;
}else if(m.key(n).comment == "Pos1"){
ease(time,t1,t2,Pos0,Pos1);
}else if(m.key(n).comment == "Pos2"){
ease(time,t1,t2,Pos1,Pos2);
}else if(m.key(n).comment == "Pos3"){
ease(time,t1,t2,Pos2,Pos3);
}else{
Pos3;
}
}else{
Pos0;
}
As far as easing goes the only control you currently have is the “move time” slider, unless you want to replace AE’s ease() with your own ease function, which wouldn’t be too hard–you could use one of the Penner eases, but you’d have to pick one.
-
Dan Ebberts
January 19, 2022 at 4:17 pmActually, there is a way to double up on the built-in ease() that I forgot about. You can do something like this:
Pos0 = thisComp.layer("Start").transform.position;
Pos1 = thisComp.layer("Position 1").transform.position;
Pos2 = thisComp.layer("Position 2").transform.position;
Pos3 = thisComp.layer("Position 3").transform.position;
moveTime = effect("moveTime")("Slider");
m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if (n > 0){
t1 = m.key(n).time;
t2 = t1 + moveTime;
t = ease(time,t1,t2,0,1);
if (m.key(n).comment == "Start"){
Pos0;
}else if(m.key(n).comment == "Pos1"){
ease(t,Pos0,Pos1);
}else if(m.key(n).comment == "Pos2"){
ease(t,Pos1,Pos2);
}else if(m.key(n).comment == "Pos3"){
ease(t,Pos2,Pos3);
}else{
Pos3;
}
}else{
Pos0;
}
-
Scott Green
January 20, 2022 at 12:16 pmThanks Dan, which value is it that controls the amount of ease?
Is it the number 1 in this line?
“t = ease(time,t1,t2,0,1);”
-
Dan Ebberts
January 20, 2022 at 1:36 pmNo, that line just applies the regular ease to the range 0-1 as the time goes from t1 to t2. Then, later in the code, ease gets applied again. So there isn’t anything that controls the amount of ease, it just gets applied twice, essentially easing the ease. You could keep doing that, but at that point you might as well use one of the Penner extreme eases like quart, quint, or exponential.
-
Scott Green
January 20, 2022 at 2:16 pmOh ok, would you mind sharing how to apply one of the other ease examples you mentioned please so I can say a exponential ease at all markers?
-
Dan Ebberts
January 20, 2022 at 4:35 pmLike this, I guess:
function myEase(t,t1,t2,v1,v2){
if(t <= t1)return v1;
if(t >= t2)return v2;
dtEase = t2 - t1;
dvEase = v2 - v1;
tEase = (t-t1)/dtEase;
if(tEase < .5)
return v1 + (dvEase/2)*Math.exp(10*(2*tEase-1));
return v1 + dvEase*(1-Math.exp(10*(1-2*tEase))/2);
}
Pos0 = thisComp.layer("Start").transform.position;
Pos1 = thisComp.layer("Position 1").transform.position;
Pos2 = thisComp.layer("Position 2").transform.position;
Pos3 = thisComp.layer("Position 3").transform.position;
moveTime = effect("moveTime")("Slider");
m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if (n > 0){
t1 = m.key(n).time;
t2 = t1 + moveTime;
if (m.key(n).comment == "Start"){
Pos0;
}else if(m.key(n).comment == "Pos1"){
myEase(time,t1,t2,Pos0,Pos1);
}else if(m.key(n).comment == "Pos2"){
myEase(time,t1,t2,Pos1,Pos2);
}else if(m.key(n).comment == "Pos3"){
myEase(time,t1,t2,Pos2,Pos3);
}else{
Pos3;
}
}else{
Pos0;
}
Log in to reply.