FORUMS: list search recent posts

On any Keyframe on slider 1, cycle value on Slider 2

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Colin Purves
On any Keyframe on slider 1, cycle value on Slider 2
on May 24, 2015 at 10:13:40 pm

Hi guys,

Really hope you can help me. I've been researching for two days. I'm setting up an automated camera. I'm nearly fully automated at last but am stuck at the last hurdle.

What I want to do is: On any Keyframe on slider 1, cycle through one of four values on Slider 2

I have a solid with two sliders on it

What I need is an expression to do this

Slider 1: Keyframe 1 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 1

Slider 1: Keyframe 2 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 2, and creates another keyframe half a sec later with value 3

Slider 1: Keyframe 3 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 4, and creates another keyframe half a sec later with value 1 <-- NOTE begining of value cycle

Slider 1: Keyframe 4 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 2, and creates another keyframe half a sec later with value 3

I hope I've explained this suitably.

Colin


Return to posts index

Dan Ebberts
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 5:45:00 am

An expression can't create keyframes, but you still might be able to get the result you're after. Where do the preset values come from?

Dan



Return to posts index

Colin Purves
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 4:58:01 pm

Thanks Dan for helping me out! You are a star!

I'm trying to get the camera to rotate around each new target for the camera, first left to right, then alternatively right to left. Each new camera target is set as a keyframe in Slider 1. Slider 2 will be a Controller for the camera's x position relative to the target x position on Slider 1.

The camera is switching targets fairly regularly to music. Presently I have the four values as keyframes on Slider 2 and then use loopOut(); to repeat them. It almost works, but it eventually loses sync with the timing of the camera switching targets. I have 25 targets in 2 mins.

My four preset values could be set as values in the expression code if need be. I'm hoping that would be like this?

v1 = -1500;
v2 = -750;
v3 = 1500;
v4 = 750;

Actually after a bit of research last night the requirement has had a small simplification.

Slider 1: Keyframe 1 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 1 (Result camera pan start position)

Slider 1: Keyframe 2 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 2 (Result camera pan end position)

Slider 1: Keyframe 3 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 3 (Result camera pan start position)

Slider 1: Keyframe 4 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 4 (Result camera pan end position)

Slider 1: Keyframe 5 set manually
Slider 2: Expression creates keyframe at the same point in time with preset value 1 <-- NOTE start of value cycle;

Any advice would be really appreciated.

Colin


Return to posts index


Dan Ebberts
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 5:22:58 pm

Something like this, maybe:


v1 = -1500;
v2 = -750;
v3 = 1500;
v4 = 750;
s = effect("Slider Control")("Slider");
if (time < s.key(2).time)
linear(time,s.key(1).time,s.key(2).time,v1,v2)
else if (time < s.key(3).time)
linear(time,s.key(2).time,s.key(3).time,v2,v3)
else if (time < s.key(4).time)
linear(time,s.key(3).time,s.key(4).time,v3,v4)
else
linear(time,s.key(4).time,s.key(5).time,v4,v1);



Dan



Return to posts index

Colin Purves
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 5:39:00 pm
Last Edited By Colin Purves on May 25, 2015 at 5:39:37 pm

Thanks Dan. This is so very near what I wanted now. I'm very lucky you were around. I'm so grateful as I need to create this sort of camera move on loads of projects.

Is there a way to make the code work so its dynamic - in other words, if I was to add more than 5 targets... Like 25 say, it would be great if the code could spot that I now have 25 keyframe targets on Slider 1 and so loop the values for the 25 targets? Would that be a "while" statement of some sort?

Col


Return to posts index

Dan Ebberts
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 6:06:18 pm

What values would it use?

Dan



Return to posts index


Colin Purves
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 6:39:55 pm

It would be the same ones - they'd repeat as necessary. So...

v1 = -1500;
v2 = -750;
v3 = 1500;
v4 = 750;

I'm hoping for a result where a camera would:
i) pan left to right on odd numbered keyframes (e.g. 1,3,5,7,9,... to however many there are on slider 1)
ii) pan right to left on even numbered keyframes (e.g. 2,4,6,8,... to however many there are on slider 1)
iii) I could add a few extra targets if needed and the expression code wouldn't need to be altered on slider 2 - it would detect the additional keyframes on slider 1.

Is this possible do you think Dan? Bit of a coding challenge!

Colin


Return to posts index

Dan Ebberts
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 6:57:07 pm

Play around with this:


v = [-1500, -750, 1500, 750];
s = effect("Slider Control")("Slider");
n = 0;
if (s.numKeys > 0){
n = s.nearestKey(time).index;
if (time < s.key(n).time) n--;
}
if (n > 0){
if (n < s.numKeys){
t1 = s.key(n).time;
t2 = s.key(n+1).time;
v1 = v[(n-1)%v.length];
v2 = v[n%v.length];
linear(time,t1,t2,v1,v2)
}else{
v [(s.numKeys-1)%v.length];
}
}else if (s.numKeys > 0){
v[0]
}else{
value;
}



Dan



Return to posts index

Colin Purves
Re: On any Keyframe on slider 1, cycle value on Slider 2
on May 25, 2015 at 8:14:54 pm

Dan my friend, you are a total genius! You did it! Thank you so much. Something for the Tip Jar on your site incoming!

Col


Return to posts index

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