- January 29, 2016 at 11:07 pm
Hi! I’ve been stumped trying to get an animation to work without hand animating positions – in an effort to save keyframes and time. I’ve got five nulls that are positioned from top to bottom, and i’d like to make it so that if i animate the position of the top null, the rest follow suit/evenly distribute. i’ve been trying to figure out a way to do it, and i feel like i’ve got some start by using an average expression, but this only gives me the midpoint, essentially the third null. i’m not sure of the math that it would take for the rest of the nulls. currently i have:
function average(a, b)
return (a + b) / 2;
average(thisComp.layer("001").transform.yPosition, thisComp.layer("005").transform.yPosition );
but if i change the value from 2, it doesn’t stay inside of the parameters of 001 and 005 position. i’m clueless. essentially it’s like i want the distribute layers button, but in an expression. i’d been told that i should try an ik but i don’t really need rotation.
any help would be greatly appreciated, thank you.
- January 30, 2016 at 6:54 am
Give the top null the name “Start Null” and the bottom one the name “End Null” and use the following for the in-between layer positions:
start_layer = thisComp.layer("Start Null");
end_layer = thisComp.layer("End Null");
pos_start = start_layer.transform.position;
pos_end = end_layer.transform.position;
index_start = start_layer.index;
index_end = end_layer.index;
layer_count = index_end - index_start;
this_layer_pos = pos_start + (pos_end-pos_start)/layer_count*(index-index_start)
This will work for any number of layers as long as the start layer and end layer stay at the top and bottom of the nulls stack and there are no other intervening layers.
Log in to reply.