Set expression a keyframe value?

Scripting for After Effects

Set expression a keyframe value?

Postby minhpro_xo on 07/5/2016, 10:44 am

Hi,
I'm doing a project in which I have a 3D layer and a camera
In this project I want to animate the 3D Layer's position so it flies toward the camera. I've set 2 keyframes on the layer, the first one is its original position, and the second one is my camera's position.
The thing is, whenever I change the position of the camera, I have to manually change the value of my 3D layer's second keyframe.
I've tried linking the 3d layer to my camera but it didn't work because when I moved the camera, the 2 keyframes moved as well, meanwhile I need to keep my first position unchanged.
So is there any way that I can link the value of my second keyframe to the camera position while maintaining the first one?
I hope that I was clear.
Thank you
minhpro_xo
 
Posts: 2
Joined: 12/9/2014, 10:32 pm

Re: Set expression a keyframe value?

Postby star+circle on 07/5/2016, 11:24 am

Like this:

Code: Select all
p1 = transform.position.valueAtTime(key(1).time);
p2 = thisComp.layer("Camera 1").transform.position;
linear(time, key(1).time, key(2).time, p1, p2)
star+circle
 
Posts: 745
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Set expression a keyframe value?

Postby minhpro_xo on 07/5/2016, 8:32 pm

Thank you star+circle, your expression works. But now a have a new problem. I want to animate my 3D layer so that it flies on a curved line. I've edited the trajectory of the object but the linear expression makes it flies only on the line segment. Any idea please?
minhpro_xo
 
Posts: 2
Joined: 12/9/2014, 10:32 pm

Re: Set expression a keyframe value?

Postby star+circle on 07/5/2016, 10:31 pm

This way it starts out in the keyframed direction but ends up at camera position:

Code: Select all
p1 = transform.position.valueAtTime(key(1).time);
p2 = thisComp.layer("Camera 1").transform.position;
tween = linear(time, key(1).time, key(2).time, 0, 1);
value + tween*(p2-value)


From the camera point of view it follows the path all the way, so you can create the exact motion path you want.
star+circle
 
Posts: 745
Joined: 12/6/2014, 3:07 pm
Location: Finland


Return to After Effects Expressions