Activity › Forums › Adobe After Effects Expressions › Use markers to control camera position?
-
Use markers to control camera position?
Posted by Zoe Woodworth on December 7, 2010 at 9:20 pmIs it possible to control a camera’s position based on what the current comp marker is?
For example, imagine a comp with 25 markers. All the markers have one of three names: “Wide” , “John” , and “Justin”. Any time that we encounter a “Wide” marker, I want to set the active camera position to x,y,z. Any time we encounter a “John” marker, I want to change the camera position to a,b,c… and so on.
If I could do something like this, it would save me SO much time from having to copy and paste keyframes manually!
Any help would be greatly appreciated!
Brie Claytonreplied 2 years, 8 months ago 3 Members · 13 Replies
-
13 Replies
-
Dan Ebberts
December 8, 2010 at 12:05 amSomething like this should work:
widePos = [200,100,0];
johnPos = [100,200,0];
justinPos = [300,200,0];C = thisComp;
n = 0;
if (C.marker.numKeys > 0){
n = C.marker.nearestKey(time).index;
if (C.marker.key(n).time > time){
n--;
}
}
if (n > 0){
if (C.marker.key(n).comment.toLowerCase() == "wide"){
widePos;
}else if(C.marker.key(n).comment.toLowerCase() == "john"){
johnPos;
}else if(C.marker.key(n).comment.toLowerCase() == "justin"){
justinPos;
}else{
value;
}
}else{
value;
}
Dan
-
Zoe Woodworth
December 8, 2010 at 4:33 pmWoo hoo! Thank you Dan! You have no idea how much easier that makes my life :).
-
Zoe Woodworth
December 9, 2010 at 4:20 pmFollow-up question: Could this be done with layer markers, instead of composition markers? Could the expression refer to such-and-such layer’s markers?
-
Dan Ebberts
December 10, 2010 at 12:53 amSure. The simplest way would probably just be to change this:
C = thisComp;
to this:
C = thisComp.layer(“your layer”);
If it were me, I’d probably also change the variable name to “L” (because it now represents a layer instead of a comp) and change “C.” to “L.” everywhere in the expression.
Dan
-
Dan Ebberts
December 8, 2021 at 4:39 pmYes, the expression goes on the camera’s position property. I’ve cleaned it up a little:
Pos01 = [200,100,0];
Pos02 = [100,200,0];
Pos03 = [300,200,0];
m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if (n > 0){
if (m.key(n).comment == "Pos01"){
Pos01;
}else if(m.key(n).comment == "Pos02"){
Pos02;
}else if(m.key(n).comment == "Pos03"){
Pos03;
}else{
value;
}
}else{
value;
}
-
Dan Ebberts
December 9, 2021 at 5:36 pmSomething like this, maybe:
Pos01 = [200,100,0];
Pos02 = [100,200,0];
Pos03 = [300,200,0];
moveTime = 0.3;
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 == "Pos01"){
ease(time,t1,t2,valueAtTime(t1),Pos01);
}else if(m.key(n).comment == "Pos02"){
ease(time,t1,t2,Pos01,Pos02);
}else if(m.key(n).comment == "Pos03"){
ease(time,t1,t2,Pos02,Pos03);
}else{
value;
}
}else{
value;
}
-
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;
}
-
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.
-
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;
}
Reply to this Discussion! Login or Sign Up